fstream fs;
string line,str;
fs.open("D::\\txt");
if (!fs) {
cout << "cannot open the file" << endl;
return -1;
}
while (getline(fs, line)) {
line += '\n';
str += line;
}
c++ 把文件转换成string
最新推荐文章于 2023-04-20 19:52:29 发布
fstream fs;
string line,str;
fs.open("D::\\txt");
if (!fs) {
cout << "cannot open the file" << endl;
return -1;
}
while (getline(fs, line)) {
line += '\n';
str += line;
}