我想用一個無限循環來讀Person結構(名字,年齡,薪水)。我想在用戶輸入名稱爲'x'時打破循環。當讀取結構數據時CPP infinit while循環錯誤?
#include <iostream>
#include <vector>
using namespace std;
struct Person
{
char name[50];
int age;
float salary;
};
int main(int argc, const char * argv[]) {
Person p1;
vector <Person> p1_vec;
while (true) {
cout << "Enter Full name or simply 'x' to exit: ";
cin.get(p1.name, 50);
bool next_entry = strcmp(p1.name,"x");
if (!next_entry) {
break;
}
cout << "Enter age: ";
cin >> p1.age;
cout << "Enter salary: ";
cin >> p1.salary;
p1_vec.push_back(p1);
}
}
請問Q/A指南知道如何提問。 – Sam
那麼_actually_發生了什麼?問題是什麼? –