Converting c++ string to int

Posted by skazhy on Stack Overflow See other posts from Stack Overflow or by skazhy
Published on 2011-01-12T13:30:32Z Indexed on 2011/01/12 13:53 UTC
Read the original article Hit count: 183

Filed under:
|
|

Hi!

I have the following data in a c++ string

John Doe 01.01.1970

I need to extract the date and time from it into int variables. I tried it like this:

int last_space = text_string.find_last_of(' ');
int day = int(text_string.substr(last_space + 1, 2));

But I got invalid cast from type ‘std::basic_string’ to type ‘int’. When I extract the "John Doe" part in another string variable, all works fine. What's wrong?

I am trying to compile it with g++ -Wall -Werror.

© Stack Overflow or respective owner

Related posts about c++

Related posts about string