不知道为什么,一遇到第一个for里面的getline,就开始报错,什么都无法输入
之前在网上搜,说是在前面的cin后面加cin.ignore();,但是还是没有用
#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <limits>
using namespace std;
struct people
{
string name;
string rankList[500];
int count; //表示已经进行选择的次数
};
int inverse(people girl_, string boy_name, int num);
int main()
{
int n;
people *boy = new people[n], *girl = new people[n];
map<string, string> match;
queue<people> freeboy; //表示还未进行配对的男生
map<string, people> girl_name;
map<string, people> boy_name;
cout << "Plaese input the number of matches to make" << endl;
cin >> n;
cin.ignore();
cout << "Plaese input the rank list" << endl;
for (int i = 0; i < n; i++)
{
getline(cin, boy[i].name,' ');
freeboy.push(boy[i]);
boy_name[boy[i].name] = boy[i];
for (int j = 0; j < n; j++)
{
getline(cin, boy[i].rankList[j]);
}
cout << endl;
你getline()后面加一个空格是什么意思?改成:
getline(cin, boy[i].name);
还有,你后面还少了两个大括号。