cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
Beginners
How to convert a string type variable in
How to convert a string type variable into an integer?
Jul 6, 2011 at 7:59pm UTC
alendrex
(18)
Hi everybody!
Does anybody know any function that converts a string type variable to an integer type.For eaxample:
string year="2011";
int number=function(year);
so it returns
number=2011;
I just want the name of the function and the standard library that contains it.
Thank you!
Jul 6, 2011 at 8:04pm UTC
bl4ckb3rry
(36)
Try this:
http://www.cplusplus.com/reference/clibrary/cstdlib/atoi/
Happy coding!
Jul 6, 2011 at 8:05pm UTC
webJose
(2948)
This has to be one of the most FAQ's in C++ these days. The Net can answer you in seconds:
http://tinyurl.com/6x9u53s
Similar posts are abundant, even in this forum.
Jul 6, 2011 at 8:15pm UTC
alendrex
(18)
Thank you guys , but it seems tha atoi() function accepts only char type variable.I need a function that has for argument a string type variable.
For axample:
atoi() works with char year[4]="2011" but it doesn't take as argument string year="2011" .
Last edited on
Jul 6, 2011 at 8:17pm UTC
Jul 6, 2011 at 8:27pm UTC
alendrex
(18)
I just find a way using istringstream type , defined at <sstream> library.
Jul 6, 2011 at 8:56pm UTC
alendrex
(18)
Or it can be used used like this :
string year="2011";
int y=atoi(year.c_str());
y=2011;
Topic archived. No new replies allowed.