我有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