|
-
April 3rd, 2003, 05:06 PM
#1
Simple Question
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
-
April 3rd, 2003, 05:10 PM
#2
I believe this will work:
atoi(str.c_str());
you are using an STL string and atoi expects a C style char *
-
April 3rd, 2003, 05:38 PM
#3
This also will work:
Code:
#include <sstream>
int main(int argc, char* argv[])
{
string str = "5";
int i;
stringstream ss(str);
ss >> i;
return 0;
}
Yeah that's a lot of temporary variable creation, huh? Well you're
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|