C++ 读写文件安全又简洁的简单实例
成都创新互联基于成都重庆香港及美国等地区分布式IDC机房数据中心构建的电信大带宽,联通大带宽,移动大带宽,多线BGP大带宽租用,是为众多客户提供专业服务器托管报价,主机托管价格性价比高,为金融证券行业成都服务器托管,ai人工智能服务器托管提供bgp线路100M独享,G口带宽及机柜租用的专业成都idc公司。
实例代码:
#include <string> #include <iostream> #include <fstream> using namespace std; int get_file_content(string sFileName, string& sFileContent); int main(int argc, char* argv[]) { string sFileContent; get_file_content("./test", sFileContent); cout << sFileContent << endl; return 0; } int get_file_content(string sFileName, string& sFileContent) { ifstream ifs (sFileName.c_str(), ifstream::in); sFileContent.clear(); char c; while (ifs.get(c)){ sFileContent.append(1, c); } ifs.close(); return 0; } int set_file_content(string sFileName, string& sFileContent) { ofstream ofs(sFileName.c_str(), ofstream::binary); size_t nCount = sFileContent.size(); ofs.write (sFileContent.c_str(), nCount); ofs.close(); return nCount; }
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
网站名称:C++读写文件安全又简洁的简单实例
本文地址:https://www.cdcxhl.com/article18/gjhegp.html
成都网站建设公司_创新互联,为您提供企业网站制作、用户体验、全网营销推广、软件开发、企业建站、App开发
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联