读取文件到内存
http://www.cplusplus.com/reference/fstream/fstream/open/
#include
int main () {
std::fstream fs;
fs.open ("test.txt", std::fstream::in | std::fstream::out | std::fstream::app);
fs << " more lorem ipsum";
fs.close();
return 0;
}
这是例子
打开文件流后读取每一行数据到内存,用getline()函数就行
再删除最后一个换行符写进文件就行
ifstream file("test.txt", ios::in);
string buf;
while (!file)
{
getline(file, buf);
if (!file) //注意这个判断,发现是末尾就不输出换行符到文件
{
file_write << buf << endl;
}
else file_write << buf;
}
希望能帮助到你