(Unsolved problem) C++ about the problem that the cin stream cannot be restored after while (cin >> ). Anyone who knows how to restore the cin stream is very grateful! ! !

#include <iostream>
#include <string>
using namespace std;

int main()
{
string str;
//下面这个循环我用文件结束符结束后,后续调用cin.clear()
while(cin >> str)
        cout << str << " ";
cin.clear();
string str_1;
//虽然前面调用clear,但是下面这个cin还是不能用为什么?哪位告诉我下,不胜感激。
cin >> str_1;
cout << str_1 << endl;

return 0;
}
~                                                                            
~     

 

Guess you like

Origin blog.csdn.net/digitalkee/article/details/112910447