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. a simple question

a simple question

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

    I want to convert "abcd" into ASCII code but I met a strange problem. My code is below. char *s="abcd"; int br[100]; for(int i=0;i<4;i++) { br[i]=__toascii(s[i]); cout << br[i] << "\n"; } string kkb=""; kkb=kkb.insert(0,br[1].ToString()); cout << kkb; and there is an error at kkb=kkb.insert(0,br[1].ToString()); error C2664: 'std::basic_string<_Elem,_Traits,_Ax> &std::basic_string<_Elem,_Traits,_Ax>::insert(__w64 unsigned int,const std::basic_string<_Elem,_Traits,_Ax> &)' : cant convert argument 2 from 'System::String ^' to 'const std::basic_string<_Elem,_Traits,_Ax> &'a It's very strange that I change the code kkb=kkb.insert(0,br[1].ToString()); into kkb=kkb.insert(0,"a string"); then it works. I dont understand that both them are string. why as long as I put the string variable int the function, it has an error? Can somebody help me? Thanks a lot. minihotto

    W T S 3 Replies Last reply
    0
    • M minihotto

      I want to convert "abcd" into ASCII code but I met a strange problem. My code is below. char *s="abcd"; int br[100]; for(int i=0;i<4;i++) { br[i]=__toascii(s[i]); cout << br[i] << "\n"; } string kkb=""; kkb=kkb.insert(0,br[1].ToString()); cout << kkb; and there is an error at kkb=kkb.insert(0,br[1].ToString()); error C2664: 'std::basic_string<_Elem,_Traits,_Ax> &std::basic_string<_Elem,_Traits,_Ax>::insert(__w64 unsigned int,const std::basic_string<_Elem,_Traits,_Ax> &)' : cant convert argument 2 from 'System::String ^' to 'const std::basic_string<_Elem,_Traits,_Ax> &'a It's very strange that I change the code kkb=kkb.insert(0,br[1].ToString()); into kkb=kkb.insert(0,"a string"); then it works. I dont understand that both them are string. why as long as I put the string variable int the function, it has an error? Can somebody help me? Thanks a lot. minihotto

      W Offline
      W Offline
      With_problem
      wrote on last edited by
      #2

      may be as i guess caz you are using it after the {} so it has error if you use this string inside {} it will work fine

      1 Reply Last reply
      0
      • M minihotto

        I want to convert "abcd" into ASCII code but I met a strange problem. My code is below. char *s="abcd"; int br[100]; for(int i=0;i<4;i++) { br[i]=__toascii(s[i]); cout << br[i] << "\n"; } string kkb=""; kkb=kkb.insert(0,br[1].ToString()); cout << kkb; and there is an error at kkb=kkb.insert(0,br[1].ToString()); error C2664: 'std::basic_string<_Elem,_Traits,_Ax> &std::basic_string<_Elem,_Traits,_Ax>::insert(__w64 unsigned int,const std::basic_string<_Elem,_Traits,_Ax> &)' : cant convert argument 2 from 'System::String ^' to 'const std::basic_string<_Elem,_Traits,_Ax> &'a It's very strange that I change the code kkb=kkb.insert(0,br[1].ToString()); into kkb=kkb.insert(0,"a string"); then it works. I dont understand that both them are string. why as long as I put the string variable int the function, it has an error? Can somebody help me? Thanks a lot. minihotto

        T Offline
        T Offline
        ThatsAlok
        wrote on last edited by
        #3

        minihotto wrote:

        I dont understand that both them are string. why as long as I put the string variable int the function, it has an error?

        better post it in it specific forum Managed C++[^]

        "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

        cheers, Alok Gupta VC Forum Q&A :- I/ IV Support CRY- Child Relief and You

        1 Reply Last reply
        0
        • M minihotto

          I want to convert "abcd" into ASCII code but I met a strange problem. My code is below. char *s="abcd"; int br[100]; for(int i=0;i<4;i++) { br[i]=__toascii(s[i]); cout << br[i] << "\n"; } string kkb=""; kkb=kkb.insert(0,br[1].ToString()); cout << kkb; and there is an error at kkb=kkb.insert(0,br[1].ToString()); error C2664: 'std::basic_string<_Elem,_Traits,_Ax> &std::basic_string<_Elem,_Traits,_Ax>::insert(__w64 unsigned int,const std::basic_string<_Elem,_Traits,_Ax> &)' : cant convert argument 2 from 'System::String ^' to 'const std::basic_string<_Elem,_Traits,_Ax> &'a It's very strange that I change the code kkb=kkb.insert(0,br[1].ToString()); into kkb=kkb.insert(0,"a string"); then it works. I dont understand that both them are string. why as long as I put the string variable int the function, it has an error? Can somebody help me? Thanks a lot. minihotto

          S Offline
          S Offline
          Steve S
          wrote on last edited by
          #4

          Yup. System::String is a Managed C++ string, while std::string is an STL string. You need a way of getting the contents of the first in a format that the STL string operator(s) can understand. You'd do better asking in the Managed C++ forum, I think.

          Steve S Developer for hire

          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