[英]std::getline(input, d.info) not working
I already know this will get marked as duplicate, but I have already tried every solution that I could find and then my own, none of which worked.我已经知道这会被标记为重复,但我已经尝试了我能找到的所有解决方案,然后是我自己的解决方案,但没有一个有效。 The error messages keep telling me that it expects a ")" after input, but I need it to write the info it is reading to the backup file.错误消息不断告诉我它在输入后需要一个“)”,但我需要它将它正在读取的信息写入备份文件。 Any help would be appreciated.任何帮助,将不胜感激。
class Data{
public:
const unsigned static int MAXIMUM_DATA = 4100u;
const static int x = 0;
string userName[MAXIMUM_DATA] = {};
string nickName[MAXIMUM_DATA] = {};
string role[MAXIMUM_DATA] = {};
string fName[MAXIMUM_DATA] = {};
string lName[MAXIMUM_DATA] = {};
string email[MAXIMUM_DATA] = {};
friend std::istream& operator>>(std::istream& input, Data& d);
};
std::istream& operator>>(std::istream& input, Data& d){
std::istream& getline(input, d.userName);
std::istream& getline(input, d.role);
std::istream& getline(input, d.fName);
std::istream& getline(input, d.lName);
std::istream& getline(input, d.nickName);
std::istream& getline(input, d.email);
return input;
}
Data d;
while(myfile >> d){
database.push_back(d);
}
One of you issues is that the std::getline
looks more like a function declaration.你们中的一个问题是std::getline
看起来更像是一个函数声明。 Change to:改成:
getline(input, /*...*/);
If you are emulating a database you may want to use a table of records.如果您正在模拟数据库,您可能需要使用记录表。
You could define a record as:您可以将记录定义为:
class Data_Record
{
public:
string userName;
string nickName;
string role;
string fName;
string lName;
string email;
friend std::istream& operator>>(std::istream& input, Data_Record& dr);
};
You database can be as simple as:您的数据库可以很简单:
std::vector<Data_Record> database;
Looks like this is what you intended to do.看起来这就是你想要做的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.