C++ C++;开关结构(最后一种情况下运行两次)
这不是因为C++ C++;开关结构(最后一种情况下运行两次),c++,while-loop,switch-statement,C++,While Loop,Switch Statement,这不是因为开关结构,而是因为eof调用:函数只有在尝试读取下一项失败后才开始返回true 将循环更改为无限循环(;)或while(true),无所谓),并在读取数据后执行eof检查。如果得到true,请使用break结束循环。否则,继续执行开关语句 循环的结构应如下所示: 157744232 b 253453534 r 335345435 R 445345345 B 545345345 t for (;;) { cout << "The account number is:
开关
结构,而是因为eof
调用:函数只有在尝试读取下一项失败后才开始返回true
将循环更改为无限循环(;)或while(true)
,无所谓),并在读取数据后执行eof
检查。如果得到true
,请使用break
结束循环。否则,继续执行开关
语句
循环的结构应如下所示:
157744232 b
253453534 r
335345435 R
445345345 B
545345345 t
for (;;) {
cout << "The account number is: ";
if (!(inFile >> accountNumber))
break;
cout << accountNumber<<"\n";
cout << "The customer type: "
<< "R or r (Residential), "
<< "B or b (Business): ";
if (!(inFile >> customerType))
break;
cout << customerType << endl;
switch (customerType) {
... // The rest of your code
}
}
(;;)的{
cout>帐号)
打破
cout这不是因为开关
结构,而是因为eof
调用:函数只有在尝试读取下一项失败后才开始返回true
将循环更改为无限循环(;)
或while(true)
,这无关紧要),并在读取数据后执行eof
检查。如果得到true
,请使用break
结束循环。否则,继续执行switch
语句
循环的结构应如下所示:
157744232 b
253453534 r
335345435 R
445345345 B
545345345 t
for (;;) {
cout << "The account number is: ";
if (!(inFile >> accountNumber))
break;
cout << accountNumber<<"\n";
cout << "The customer type: "
<< "R or r (Residential), "
<< "B or b (Business): ";
if (!(inFile >> customerType))
break;
cout << customerType << endl;
switch (customerType) {
... // The rest of your code
}
}
(;;)的{
cout>帐号)
打破
cout在文件上编写循环时,应使用以下内容:
157744232 b
253453534 r
335345435 R
445345345 B
545345345 t
for (;;) {
cout << "The account number is: ";
if (!(inFile >> accountNumber))
break;
cout << accountNumber<<"\n";
cout << "The customer type: "
<< "R or r (Residential), "
<< "B or b (Business): ";
if (!(inFile >> customerType))
break;
cout << customerType << endl;
switch (customerType) {
... // The rest of your code
}
}
或者这个:
while( inFile >> somevar ) {
...
}
这是常见的错误。在文件上编写循环时,应使用以下内容:
157744232 b
253453534 r
335345435 R
445345345 B
545345345 t
for (;;) {
cout << "The account number is: ";
if (!(inFile >> accountNumber))
break;
cout << accountNumber<<"\n";
cout << "The customer type: "
<< "R or r (Residential), "
<< "B or b (Business): ";
if (!(inFile >> customerType))
break;
cout << customerType << endl;
switch (customerType) {
... // The rest of your code
}
}
或者这个:
while( inFile >> somevar ) {
...
}
这是一个常见的错误。对于这样的问题, C++是相当重的。为什么不使用Python、Ruby或者NoDEjs?@ TADMAN,如果他正在攻读C++类,我认为他不会通过转入Python的答案获得好的成绩。可能的Barmar Ah的副本,我没有注意到这个要求。C++对于这样的问题是相当重的。为什么不呢?Typyon,Ruby甚至Nojjs?@ TADMAN如果他参加C++课程,我认为他不会通过转入Python的答案获得好成绩。可能的Barmar Ah @的副本,我没有注意到这个要求。