C/C++ 读写文件

//头文件
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
using namespace std;

//写入文件
void writeFile()

{

ofstream writeFile;
//当文件名使有绝对路径时如"D:\workspace\File\DpRecvCtrlSet.ini"
//要注意 / 是个转义字符 应写成 "D:\\workspace\\File\\DpRecvCtrlSet.ini" 形式

writeFile.open(L"wzy.txt", ios::app);
writeFile << 1 << " " << 2 <<" "<< std::endl;
writeFile.close();
}

//读出文件
void readeFile()
{
string value;
ifstream readFile;
readFile.open(L"wzy.txt");
//readFile.open(fileName.c_str());
while(getline(readFile, value))
std::cout << value;
}

你可能感兴趣的:(C++,c,读写文件)