1. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Rep Power

    CString to string

    here is my question. I am new to VC++, but not C++.
    I would like to pass a variable of type CString (VC++) to a string in (C++).
    I currently am saving the variable of type CString in a file. Then in my C++ code open the file and read it out as type string.
    Is there just some short conversion.

    CString s1;
    string s2;

    could you do this? If not then what?

    Thanks for the help,

    (oh, by the way, how do you put your pic in the site?)
    This message is a natural product made from recycled electrons. The slight
    variations in spelling and grammar enhance its individual character and
    beauty and in no way are to be considered flaws or defects.
  2. #2
  3. I'm Baaaaaaack!
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Jul 2003
    Rep Power
    Here is some background to CString: http://msdn.microsoft.com/library/de...fc_cstring.asp.

    Here is some code:

    #include <stdio.h>
    #include <afx.h>
    #include <string>
    using namespace std;
    int main(){
        CString cstr;
        string str;
        cstr = "this is a CString";
        str = "this is a string";
        printf("%s\n%s\n", cstr, str.c_str());
        cstr = "This is a str stuffed into a CString: ";
        cstr += str.c_str();
        printf("%s\n", cstr);
        return 0;
    Dunno nutin about the pics.

    My blog, The Fount of Useless Information http://sol-biotech.com/wordpress/
    Free code: http://sol-biotech.com/code/.
    Secure Programming: http://sol-biotech.com/code/SecProgFAQ.html.
    Performance Programming: http://sol-biotech.com/code/PerformanceProgramming.html.
    LinkedIn Profile: http://www.linkedin.com/in/keithoxenrider

    It is not that old programmers are any smarter or code better, it is just that they have made the same stupid mistake so many times that it is second nature to fix it.
    --Me, I just made it up

    The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore, all progress depends on the unreasonable man.
    --George Bernard Shaw
  4. #3
  5. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Rep Power
    Thanks, I will play around with this for a bit

IMN logo majestic logo threadwatch logo seochat tools logo