Linux下C++读写txt文件

xiaoxiao2021-02-28  73

int readWriteFile(string srcFile, string dstFile) { cout <<"in File" << srcFile << endl; cout <<"out File" << dstFile << endl; ifstream in(srcFile.c_str()); if (!in.is_open()) { cout << "open src File Error opening file" << endl; return -1; } ofstream out(dstFile.c_str()); if(!out.is_open()) { cout << "open dst File Error opening file" << endl; return -1; } char* buffer = new char[1024]; while (!in.eof()) { in.read(buffer, 1024); cout << buffer << endl; out.write(buffer, 1024); } in.close(); out.close(); return 0; }
转载请注明原文地址: https://www.6miu.com/read-78321.html

最新回复(0)