简体   繁体   中英

Extract numbers from string

how do i get and store two numbers from a string using istringstream

For eg.

sum from 2 to 3

i want to read and store 2 and 3 not necessarily we know the position of integers occuring

You can read input using std::cin , for example. If you know your next token is a string, give it a string:

std::string str;
std::cin >> str;

Or an int:

int num;
std::cin >> num;

You should check for eof and error states as usual.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM