2 つの別々の入力に依存する while ループがあるとします。状況 1 では、while ループは値 1 を取り、状況 2 では、!cin.eof() を取る必要があります。これを効率的に行う方法はありますか?より簡潔にするには:
string hello;
cin >> hello;
if(hello == "one")
{
//make the while loop depend on value 1
}
else if(hello == "two")
{
//make the while loop depend on value !cin.eof()
}
while(/*depends on above conditional*/)
{}
私は次のようなことをしたくありません:
if(hello == "one)
{
while(1){}
}
else if(hello == "two")
{
while(!cin.eof){}
}
while ループは基本的に、それぞれの状況で同じことを行うためです。