A strange problem
-
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 -
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. minihottoI'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