利用c++的stream类
头文件:#include <fstream>
1.读文件
string strRes;
string strPath = “/opt/test/test.txt”;
if (access(strPath .c_str(), 0) == 0) //如果路径存在
{
ifstream ifFile(strPath .c_str());
ifFile >> strRes;
ifFile.close();
}
2.写文件
string strVal = “hello world”;
string strPath = “/opt/test/test.txt”;
ofstream write_file(strPath .c_str());
write_file << strVal;
write_file.close();