Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. CString error

CString error

Scheduled Pinned Locked Moved C / C++ / MFC
c++helpquestion
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    RalfPeter
    wrote on last edited by
    #1

    Hi all, I've recently gotten VC++ 2005 and am having problems with the CString class. Here three examples and the errors I'm getting: 1. AfxMessageBox("some text"); //none of the 2 overloads could convert all the argument types 2. void MyFunction(int i, CString str); ... MyFunction(1, "some text"); //cannot convert parameter 2 from 'const char [4]' to 'CString' but CString str; str = "some text"; MyFunction(1, str); //works fine 3. Also, the declaration CString str = "some text"; does not work. The error message is: error C2440: 'initializing' : cannot convert from 'const char [26]' to 'ATL::CStringT' 1> with 1> [ 1> BaseType=wchar_t, 1> StringTraits=StrTraitMFC_DLL 1> ] 1> Constructor for class 'ATL::CStringT' is declared 'explicit' 1> with 1> [ 1> BaseType=wchar_t, 1> StringTraits=StrTraitMFC_DLL 1> ] Anyone can tell me if there was a change to the CString class? Thx, Ralf. ralf.riedel@usm.edu

    L 1 Reply Last reply
    0
    • R RalfPeter

      Hi all, I've recently gotten VC++ 2005 and am having problems with the CString class. Here three examples and the errors I'm getting: 1. AfxMessageBox("some text"); //none of the 2 overloads could convert all the argument types 2. void MyFunction(int i, CString str); ... MyFunction(1, "some text"); //cannot convert parameter 2 from 'const char [4]' to 'CString' but CString str; str = "some text"; MyFunction(1, str); //works fine 3. Also, the declaration CString str = "some text"; does not work. The error message is: error C2440: 'initializing' : cannot convert from 'const char [26]' to 'ATL::CStringT' 1> with 1> [ 1> BaseType=wchar_t, 1> StringTraits=StrTraitMFC_DLL 1> ] 1> Constructor for class 'ATL::CStringT' is declared 'explicit' 1> with 1> [ 1> BaseType=wchar_t, 1> StringTraits=StrTraitMFC_DLL 1> ] Anyone can tell me if there was a change to the CString class? Thx, Ralf. ralf.riedel@usm.edu

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      IIRC, VS2005 uses Unicode for new projects for default, so try:

      AfxMessageBox(L"Some text");

      Basically, insert L before your strings (to indicate it is a Unicode string), or change your default project settings to MBCS.

      S 1 Reply Last reply
      0
      • L Lost User

        IIRC, VS2005 uses Unicode for new projects for default, so try:

        AfxMessageBox(L"Some text");

        Basically, insert L before your strings (to indicate it is a Unicode string), or change your default project settings to MBCS.

        S Offline
        S Offline
        Stephen Hewitt
        wrote on last edited by
        #3

        I would use the _T macro from <tchar.h>. i.e.

        AfxMessageBox(_T("Some text"));
        

        This way you can build ANSI or UNICODE builds without altering the code. Steve

        L 1 Reply Last reply
        0
        • S Stephen Hewitt

          I would use the _T macro from <tchar.h>. i.e.

          AfxMessageBox(_T("Some text"));
          

          This way you can build ANSI or UNICODE builds without altering the code. Steve

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Indeed, but, personally, I only ever build for Unicode - using the UnicoWS library for (dwindling) Win9x support. :)

          R 1 Reply Last reply
          0
          • L Lost User

            Indeed, but, personally, I only ever build for Unicode - using the UnicoWS library for (dwindling) Win9x support. :)

            R Offline
            R Offline
            RalfPeter
            wrote on last edited by
            #5

            Thanks for the replies. Got the code up and running. ralf.riedel@usm.edu

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups