int main() { vector<int> numbers; vector<string> strings; string temp; int tempint; setlocale(LC_ALL, "rus"); string str; ifstream ifstr("text.txt"); while (ifstr >> temp) { if (isdigit(temp[0])) { ifstr.clear(); ifstr.unget(); ifstr >> tempint; numbers.push_back(tempint); } else { strings.push_back(temp); } } ifstr.close(); for (int i : numbers) { cout << i << " "; } cout << endl; for (string i : strings) { cout << i << " "; } cout << endl; system("pause"); return 0; 

}

    1 answer 1

    The unget() function returns only the last character read .

    Moreover, the standard guarantees the return of only one character. Those. if you call unget() ten times - there is no certainty that more than 1 character will be returned to the stream.

    As stated in Josattis’s Standard C ++ Library, “The Standard ensures that only one call between two read operations is working correctly .