简单的文件读写

include

include

using namespace std;

void TestReadFile(){
ifstream file;
file.open(“C:/Users/Administrator/Desktop/cc.txt”, ios::in);
if (file.fail()) {
cout << “fail” << endl;
return;
}
istreambuf_iterator beg(file), end;
string str = string(beg, end);

cout << “str:” << str << endl;

file.close();
}

void TestWriteFile(){
fstream file;
file.open(“C:/Users/Administrator/Desktop/cc2.txt”, ios::out);
file << “hello” << endl;

file.close();
}

int main(){
// TestReadFile();
TestWriteFile();
return 0;
}

你可能感兴趣的:(list,IO,map)