C++文件读写
现在C++的文件读写很不方便,所以我写了一个File类,可以很轻松地读取和写入文件,直接复制黏贴注意注明版权
class File { private: string file=""; public: void setFile(string f) { file=f; } string getFile() { return file; } string readFile() { string retu=""; ifstream in(file); char got; if(in) { while(true) { in.get(got); if(in.eof()) { break; } retu+=got; } } in.close(); return retu; } bool writeFile(string str) { try { ofstream out; out.open(file, ios::app); out<<str<<endl; out.close(); return true; } catch(exception&) { return false; } } bool deleteAndWriteFile(string str) { try { ofstream out; out.open(file); out<<str<<endl; out.close(); return true; } catch(exception&) { return false; } } };
c/c++开发分享C++读写文件地址:https://blog.csdn.net/twxwjh/article/details/108697238
本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。
ctvol管理联系方式QQ:251552304
本文章地址:https://www.ctvol.com/c-cdevelopment/597493.html