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