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. convert

convert

Scheduled Pinned Locked Moved C / C++ / MFC
c++helpquestion
5 Posts 5 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.
  • D Offline
    D Offline
    durban2
    wrote on last edited by
    #1

    MFC, STUDIO 2008, Project use UNICODE CString m_sTest; m_sTest = L"Байкал"; char *m_pchar3; m_pchar3 = new char[70]; How todo m_sTest into m_pchar3? //- m_pchar3=m_sTest; // error C2440: '=' : cannot convert from 'CString' to 'char *' //- strcpy(m_pchar3, m_sTest); // error C2664: 'strcpy' : cannot convert parameter 2 from 'CString' to 'const char *' //- strcpy(m_pchar3, (TCHAR)m_sTest); // error C2440: 'type cast' : cannot convert from 'CString' to 'TCHAR' //- _tcscpy( m_pchar3, (TCHAR*)(LPCTSTR)m_sTest ); // error C2664: 'wcscpy' : cannot convert parameter 1 from 'char *' to 'wchar_t *'

    C D A E 4 Replies Last reply
    0
    • D durban2

      MFC, STUDIO 2008, Project use UNICODE CString m_sTest; m_sTest = L"Байкал"; char *m_pchar3; m_pchar3 = new char[70]; How todo m_sTest into m_pchar3? //- m_pchar3=m_sTest; // error C2440: '=' : cannot convert from 'CString' to 'char *' //- strcpy(m_pchar3, m_sTest); // error C2664: 'strcpy' : cannot convert parameter 2 from 'CString' to 'const char *' //- strcpy(m_pchar3, (TCHAR)m_sTest); // error C2440: 'type cast' : cannot convert from 'CString' to 'TCHAR' //- _tcscpy( m_pchar3, (TCHAR*)(LPCTSTR)m_sTest ); // error C2664: 'wcscpy' : cannot convert parameter 1 from 'char *' to 'wchar_t *'

      C Offline
      C Offline
      CPallini
      wrote on last edited by
      #2

      Why do you need to do that? :)

      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
      This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
      [My articles]

      1 Reply Last reply
      0
      • D durban2

        MFC, STUDIO 2008, Project use UNICODE CString m_sTest; m_sTest = L"Байкал"; char *m_pchar3; m_pchar3 = new char[70]; How todo m_sTest into m_pchar3? //- m_pchar3=m_sTest; // error C2440: '=' : cannot convert from 'CString' to 'char *' //- strcpy(m_pchar3, m_sTest); // error C2664: 'strcpy' : cannot convert parameter 2 from 'CString' to 'const char *' //- strcpy(m_pchar3, (TCHAR)m_sTest); // error C2440: 'type cast' : cannot convert from 'CString' to 'TCHAR' //- _tcscpy( m_pchar3, (TCHAR*)(LPCTSTR)m_sTest ); // error C2664: 'wcscpy' : cannot convert parameter 1 from 'char *' to 'wchar_t *'

        D Offline
        D Offline
        Dominik Reichl
        wrote on last edited by
        #3

        CHIVOTIOV wrote:

        char *m_pchar3; m_pchar3 = new char[70];

        Use TCHAR instead of char.


        Too many passwords to remember? Try KeePass Password Safe!

        1 Reply Last reply
        0
        • D durban2

          MFC, STUDIO 2008, Project use UNICODE CString m_sTest; m_sTest = L"Байкал"; char *m_pchar3; m_pchar3 = new char[70]; How todo m_sTest into m_pchar3? //- m_pchar3=m_sTest; // error C2440: '=' : cannot convert from 'CString' to 'char *' //- strcpy(m_pchar3, m_sTest); // error C2664: 'strcpy' : cannot convert parameter 2 from 'CString' to 'const char *' //- strcpy(m_pchar3, (TCHAR)m_sTest); // error C2440: 'type cast' : cannot convert from 'CString' to 'TCHAR' //- _tcscpy( m_pchar3, (TCHAR*)(LPCTSTR)m_sTest ); // error C2664: 'wcscpy' : cannot convert parameter 1 from 'char *' to 'wchar_t *'

          A Offline
          A Offline
          Akt_4_U
          wrote on last edited by
          #4

          The m_sTest is a UNICODE string. So if you want to convert this UNICODE string to char* use WideCharToMultiBye API or use CRT function wcstombs.

          prvn

          1 Reply Last reply
          0
          • D durban2

            MFC, STUDIO 2008, Project use UNICODE CString m_sTest; m_sTest = L"Байкал"; char *m_pchar3; m_pchar3 = new char[70]; How todo m_sTest into m_pchar3? //- m_pchar3=m_sTest; // error C2440: '=' : cannot convert from 'CString' to 'char *' //- strcpy(m_pchar3, m_sTest); // error C2664: 'strcpy' : cannot convert parameter 2 from 'CString' to 'const char *' //- strcpy(m_pchar3, (TCHAR)m_sTest); // error C2440: 'type cast' : cannot convert from 'CString' to 'TCHAR' //- _tcscpy( m_pchar3, (TCHAR*)(LPCTSTR)m_sTest ); // error C2664: 'wcscpy' : cannot convert parameter 1 from 'char *' to 'wchar_t *'

            E Offline
            E Offline
            Eytukan
            wrote on last edited by
            #5

            CHIVOTIOV wrote:

            / error C2664: 'wcscpy' : cannot convert parameter 1 from 'char *' to 'wchar_t *'

            Just a padding to the other replies here. As the above lines says, You are trying to squeeze a 2 Byte string (UNICODE) into a single byte string(ANSI). char , std::string , etc by default belong to the single byte representation. wchar_t, std::wstring, etc represent UNICODE representation. TCHAR is "neutral" based on the scheme used, it switches type accordingly. If you define # UNICODE in the setting, the string becomes 2 byte reps. If you don't define it, it becomes single byte. Also when you use TCHARs, you should use strings apis specific to TCHARs. (like _tcscpy) that assures complete independence to your character-set implementations. Similarly, CString switches types based on the project character-set settings.(UNICODE/Single-byte). Now you have defined UNICODE in your project settings but trying a cross-copy operation. So just figure out what needs to be done.. :)

            He never answers anyone who replies to him. I've taken to calling him a retard, which is not fair to retards everywhere.-Christian Graus

            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