Sample of C++ read/write a text file
2009-06-05 17:16
399 查看
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
const char *filename = "t.txt";
ofstream ofile;
ifstream ifile;
//write
ofile.open(filename);
ofile << "111111111111" << endl;
ofile << "222222222222" << endl;
ofile.close();
//read
string str;
ifile.open(filename);
while(ifile >> str)
cout << str << endl;
ifile.close();
return 0;
}
#include <fstream>
using namespace std;
int main()
{
const char *filename = "t.txt";
ofstream ofile;
ifstream ifile;
//write
ofile.open(filename);
ofile << "111111111111" << endl;
ofile << "222222222222" << endl;
ofile.close();
//read
string str;
ifile.open(filename);
while(ifile >> str)
cout << str << endl;
ifile.close();
return 0;
}
相关文章推荐
- [C++]C++小笔记之Simple File read and write-- ofstream and ifstream
- Read and write excel file with format by pandas and xlwt libraries of python
- C++ file read write
- read\write in C++ from file
- Create, Read, Write, Copy, Move and Delete a Text File using C#
- File.ReadAllText方法,File.WriteAllText方法修改文件内容
- read UTF-8 text file in C++
- io - make c++ vector read/write from/to a file - Stack Overflow
- Create, Read, Write, Copy, Move and Delete a Text File using C#
- Write a method to print the last K lines of an input file using C++
- Configure file like format of ini and read data from ini file or write data to ini file
- Something about file's read and write (C++)
- C++ » File » File Read Write Screenshots
- Create, Read, Write, Copy, Move and Delete a Text File using C# and VB.NET
- Read a Text File with VBA in Excel, and Write the Text to a Spreadsheet
- C++ IO: File Read Write
- C++ - Read / Write std::map to a file
- Cannot set the value of read-only property 'outputFile' for ApkVariantOutputImpl_Decorated{apkData=M
- ubuntu无法启动,出现attempt to read or write outside of disk hd0错误
- Call C# Code from C++ and read an array of struct which contains strings