Error while converting int to string...
-
I am trying to convert an int to string and get an error. I have the following...
string str="1";
int val;
val=atoi(str.c_str()); // Converts String to INT
val++;
itoa(val,str,10);//Converting INT to stringOn doing this I get the following error. Were could I have gone wrong?
error C2664: 'itoa' : cannot convert parameter 2 from 'class std::basic_string,class std::allocator >' to 'char *'
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be calledTHANKS.
-
I am trying to convert an int to string and get an error. I have the following...
string str="1";
int val;
val=atoi(str.c_str()); // Converts String to INT
val++;
itoa(val,str,10);//Converting INT to stringOn doing this I get the following error. Were could I have gone wrong?
error C2664: 'itoa' : cannot convert parameter 2 from 'class std::basic_string,class std::allocator >' to 'char *'
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be calledTHANKS.
string str="1"; int val; val=atoi(str.c_str()); // Converts String to INT val++; itoa(val,(char*)str.c_str(),10);//Converting INT to string
The code would serve your purpose but not be the optimized way of doing this.
Somethings seem HARD to do, until we know how to do them. ;-)_AnShUmAn_
-
I am trying to convert an int to string and get an error. I have the following...
string str="1";
int val;
val=atoi(str.c_str()); // Converts String to INT
val++;
itoa(val,str,10);//Converting INT to stringOn doing this I get the following error. Were could I have gone wrong?
error C2664: 'itoa' : cannot convert parameter 2 from 'class std::basic_string,class std::allocator >' to 'char *'
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be calledTHANKS.
See the answers given to the following queries: Asked on 12th May 2008[^] Asked on 13th May 2008[^] Asked on 14th May 2008[^] You forgot to ask it on 15th May 2008. Today is 16th May 2008 and you DID ask the same thing.
Nobody can give you wiser advice than yourself. - Cicero .·´¯`·->Rajesh<-·´¯`·. Codeproject.com: Visual C++ MVP
-
I am trying to convert an int to string and get an error. I have the following...
string str="1";
int val;
val=atoi(str.c_str()); // Converts String to INT
val++;
itoa(val,str,10);//Converting INT to stringOn doing this I get the following error. Were could I have gone wrong?
error C2664: 'itoa' : cannot convert parameter 2 from 'class std::basic_string,class std::allocator >' to 'char *'
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be calledTHANKS.
string s= "1";
strstream str;
int n;str << s;
str >> n;
n++;
str.clear();
str << n << '\0';
s = str.str();:)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke -
string str="1"; int val; val=atoi(str.c_str()); // Converts String to INT val++; itoa(val,(char*)str.c_str(),10);//Converting INT to string
The code would serve your purpose but not be the optimized way of doing this.
Somethings seem HARD to do, until we know how to do them. ;-)_AnShUmAn_
_AnShUmAn_ wrote:
(char*)str.c_str(
This is a bad idea. The return type is
const char *
and casting away theconst
is wrong and the compiler is correct in complaining.Steve