如何使用txt文件中的竖线读取数据? c ++
ifstream file_("user.txt");
std::string id;
std::string name;
std::string section;
int password;
std::string address;
std::string rank;
答案 0 :(得分:1)
类似的东西(未经测试的代码)
ifstream file_("user.txt");
if (file_.is_open())
{
string id;
string name;
string section;
string password_s;
string address;
string rank;
while (getline(file_, id, '|') &&
getline(file_, name, '|') &&
getline(file_, section, '|') &&
getline(file_, password_s, '|') &&
getline(file_, address)) {
int password = stoi(password_s);
cout << id << name << section << password << address << '\n';
}
}
else
cout << "file is not open" << endl;
system("pause");
return 0;