我有C++流的問題。我需要輸入一些數字,程序應該比較「字符串」並將其標記爲「const」「grove」等。主要問題如何輸入這些數字時,我不知道有多少用戶想輸入。我認爲最好的想法是使用-1作爲最後的「標識符」。但是如何逐個輸入這些數字(digit1 [space] digit2 [space] digit3 [space] -1)?我嘗試這樣做,如何通過cin輸入流超過2個變量
int main() {
int repeatCount = 0;
int stringCount = 0;
float digit1 = 0;
float digit2 = 0;
cout << "How many strings You have?" << endl;
cin >> iloscPowtorzen;
while(stringCount != repeatCount)
{
cin >> digit2 >> digit2;
while (digit2 != -1)
{
//HERE I HAVEN'T GOT ANY IDEA
}
stringCount++;
}
system("pause");
return 0;
}
例(它應該如何工作):
輸入
<<How many strings You have?
>>3
>>1 1 1 1 -1
>>1 2 3 4 -1
>>4 3 2 1 -1
輸出
<<const
<<grove
<<decrease
對不起,我的英語水平。 問候
什麼是'iloscPowtorzen'?應該是'repeatCount'? – Barmar