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 const char to std::string

convert const char to std::string

Scheduled Pinned Locked Moved C / C++ / MFC
c++questionhelp
3 Posts 2 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
    RedSonja
    wrote on last edited by
    #1

    After decades of fun we now have to stop using MFC in the project. How do I get this to work? I want a simple solution, because I have this about 1000 times in the code. I tried those answers which seemed obvious to me, but it does not compile. const char CODE_N = 'N'; string SK::getCode() const // was CString { return CODE_N; } 1>..\path\SK.cpp(1423) : error C2440: 'initializing' : cannot convert from 'const char' to 'std::basic_string<_Elem,_Traits,_Ax>'

    ------------- Bibo ergo sum

    C 1 Reply Last reply
    0
    • R RedSonja

      After decades of fun we now have to stop using MFC in the project. How do I get this to work? I want a simple solution, because I have this about 1000 times in the code. I tried those answers which seemed obvious to me, but it does not compile. const char CODE_N = 'N'; string SK::getCode() const // was CString { return CODE_N; } 1>..\path\SK.cpp(1423) : error C2440: 'initializing' : cannot convert from 'const char' to 'std::basic_string<_Elem,_Traits,_Ax>'

      ------------- Bibo ergo sum

      C Offline
      C Offline
      Cedric Moonen
      wrote on last edited by
      #2

      Check this article[^], things will be much clearer afterwards.

      Cédric Moonen Software developer
      Charting control [v1.5] OpenGL game tutorial in C++

      R 1 Reply Last reply
      0
      • C Cedric Moonen

        Check this article[^], things will be much clearer afterwards.

        Cédric Moonen Software developer
        Charting control [v1.5] OpenGL game tutorial in C++

        R Offline
        R Offline
        RedSonja
        wrote on last edited by
        #3

        Thankyou for your quick reply. I realise I had hit on one of the few const char definitions which only has one character. Those with more than one worked fine the way it was.

        ------------- Bibo ergo sum

        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