Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我对我的 C++ 很生疏。我想知道以以下格式读取输入的最佳方法是什么:
400 200 138 493 ...
我目前while(cin.peek()!=-1)用来检查 EOF,然后在其中,我while(cin.peek()!='\n')用来检查换行符。这对于阅读整行文本来说很好,但我怎样才能将其限制为 2 个数字和/或只抓取这 2 个数字?
while(cin.peek()!=-1)
while(cin.peek()!='\n')
int num1,num2; while(cin>>num1>>num2) { //... }
或者
string line; int num1,num2; stringstream ss; while(getline(cin,line)) { ss<<line; ss>>num1>>num2; //... }