私は現在、オプションを除いて、次にテキストの部分が続く場合に必要なプログラムを書いています。テキストがtrueの場合、コードが実行されますか?少なくとも私はそれがうまくいくと思いますが、プログラムはelseに直接行き、getline()というユーザーからの別の入力を要求しない初期条件のためにループを続けますか?なぜプログラムは入力を要求するのではなくループしていますか?
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;
int main() {
fstream gFile;
int choice;
string gb;
do {
cout << "Student Grade Book Info Program....\n";
cout << "\tPlease Select an Option: (1 or 2) \n" << endl
<< "\t1. Review Grades"
<< "\n\t2. Quit"
<< "\n\tChoose: ";
cin >> choice;
switch (choice) {
case 1:
cout << "\n\tPlease Enter the Name of the File you wish to View the Grades for: " << endl;
cout << "\n\tAvailable Grade Books: gradeBook\n" <<
"\tType in the Grade Book you would like to view. ";
getline(cin, gb);
if (gb == "gradeBook") {
cout << "execute code...";
}
else {
cout << "\nError there is no such entry in the system." << endl;
}
case 2:
break;
}
} while (choice != 2);
return 0;
}
ああ固定されています。出来た!それはすごいです、とても感謝します。 –
説明は良いですが、解決策はこれまでのところ無関係です。これは良い解決策ではありませんので、抽出演算子の前にgetlineの使用を制限してください! 'cin.flush()'と 'cin.sync()'と 'cin.ignore()'の役割は何ですか? – Raindrop7
'getline'と' std :: getline'の違いは何ですか? – Raindrop7