|
-
October 14th, 2009, 07:08 PM
#1
how to convert a string to integer with C++
Does anyone know how I could convert a string into int in C++?
I have the code ready set up but the result isn't what I expect.
example:
year = date_input.substr(second_slash, 4);
stringstream ss(year);
int in_year;
ss>> in_year;
let me know.. thanks!!
-
October 14th, 2009, 07:11 PM
#2
Re: how to convert a string to integer with C++
int in_year = atoi(ss.c_str());
-
October 14th, 2009, 07:48 PM
#3
Re: how to convert a string to integer with C++
Without questioning Superman’s suggestion, I’d like to know what didn’t work in your code.
This fragment:
Code:
std::string year("1234");
std::stringstream ss(year);
int in_year;
ss>> in_year;
produces correct result.
What did your call
Code:
year = date_input.substr(second_slash, 4);
returned? What was date_input? And what was second_slash?
Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
Convenience and productivity tools for Microsoft Visual Studio:
FeinWindows - replacement windows manager for Visual Studio, and more...
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
|