There is a line like: "40 1234567 12"
You need to parse the second line (i.e. 1234567)
How to do it?
Disclaimer: all fool protection is disabled, we believe that the format is exactly as shown.
For example: :)
string s = "40 1234567 12", get; istringstream in(s); s >> get; s >> get; Or:
s = s.substr(s.find(' ')+1); s = s.substr(0,s.find(' ')); If you need to bring not only the second word, you can do this:
#include <iostream> #include <string> #include <vector> #include <sstream> #include <iterator> using namespace std; int main() { string s; getline(cin, s); // вводим строку istringstream iss(s); // записываем все слова в вектор vector <string> a { istream_iterator<string>{iss}, istream_iterator<string>{} }; cout << a[1] << endl; // выводим второе слово return 0; } Source: https://ru.stackoverflow.com/questions/937192/
All Articles