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. Managed C++/CLI
  4. A strange problem

A strange problem

Scheduled Pinned Locked Moved Managed C++/CLI
helpquestion
2 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.
  • 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

    C 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

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      I'd recommend using sprintf or ( better ) ostringstream to do this. That would also make all your code C++, instead of the one reference to the .NET libraries.

      Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

      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