CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8

Threaded View

  1. #1
    Join Date
    Mar 2010
    Posts
    42

    Problem with converting std::string to CString

    Hi all,

    I am experiencing a problem in converting std::string to CString, and I don't know why it occurs. I am not using MFC. I just included atlstr.h.

    Here is the code I use:

    string mpname = "SCCMDC.SCCM.COM";

    CString sMPIP(mpname.c_str());

    cout << "sMPIP: " << sMPIP << endl;

    printf("Printf: &#37;s", sMPIP);
    printf("Printf2: %s", &sMPIP);

    cout returns something like this:

    sMPIP: 000000000003046F8

    While the two printfs returns something like this:

    Printf: <
    Printf: H=1

    I am not sure if the above is causing another error: adding two CStrings.

    CString sNewloc = "something" + cString1 + " something " + cString2;

    printf("new loc: %s", sNewloc);



    Am I converting it wrong or am I just printing it wrong? Can anyone help me with this?

    Thank you!
    Last edited by LeanA; May 14th, 2010 at 04:36 AM. Reason: Additional problem

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured