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 @的副本,我没有注意到这个要求。