Hi,
I have somehting like this
string str;
str = "5";
I want to convert this str to an integer 5. How can I do this . I am using atoi(str) I am getting compilation errors.
Can anyone plese help me.
thanks
rakesh
Printable View
Hi,
I have somehting like this
string str;
str = "5";
I want to convert this str to an integer 5. How can I do this . I am using atoi(str) I am getting compilation errors.
Can anyone plese help me.
thanks
rakesh
I believe this will work:
atoi(str.c_str());
you are using an STL string and atoi expects a C style char *
This also will work:
Yeah that's a lot of temporary variable creation, huh? Well you'reCode:#include <sstream>
int main(int argc, char* argv[])
{
string str = "5";
int i;
stringstream ss(str);
ss >> i;
return 0;
}
in luck if you're thinking that! Go to http://www.boost.org.
At their site, look up lexical_cast [part of the conversion library].
As an aside, are you on the Qt mailing list? There was a VERY
similar question posted on there today :)
--Paul