By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,654 Members | 936 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,654 IT Pros & Developers. It's quick & easy.

how to convert a string to number

P: 60
hi. I want to get a string as input.
If the input is an integer i want to save it to an int variable.
I know to convert a number to int. but how to convert a string to number(integer). in C++
Mar 12 '07 #1
Share this Question
Share on Google+
3 Replies


Expert 100+
P: 1,510
hi. I want to get a string as input.
If the input is an integer i want to save it to an int variable.
I know to convert a number to int. but how to convert a string to number(integer). in C++
In C++ you can use stringstream for this, see
http://www.cppreference.com/cppsstream/all.html
Mar 12 '07 #2

P: 1
hi. I want to get a string as input.
If the input is an integer i want to save it to an int variable.
I know to convert a number to int. but how to convert a string to number(integer). in C++
you can apply atoi () or atof () from the c language.

string s = "10";
int i = atoi(s.c_str());
Mar 12 '07 #3

P: 60
Thank you for the kind Help
Mar 14 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.