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!!
Re: how to convert a string to integer with C++
int in_year = atoi(ss.c_str());
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?