C++读写txt文件
2013-12-09 10:04
381 查看
code:
#include <iostream>
#include <fstream>
#include<string>
using namespace std;
int main () {
ofstream ofile ("D:\\example.txt");
if (ofile.is_open())
{
ofile << "This is a line.\n";
ofile << "This is another line.\n";
ofile.close();
}
else cout << "Unable to open file";
string line;
ifstream ifile ("D:\\example.txt");
if (ifile.is_open())
{
while ( getline (ifile,line) )
{
cout << line << '\n';
}
ifile.close();
}
else cout << "Unable to open file";
return 0;
}
#include <iostream>
#include <fstream>
#include<string>
using namespace std;
int main () {
ofstream ofile ("D:\\example.txt");
if (ofile.is_open())
{
ofile << "This is a line.\n";
ofile << "This is another line.\n";
ofile.close();
}
else cout << "Unable to open file";
string line;
ifstream ifile ("D:\\example.txt");
if (ifile.is_open())
{
while ( getline (ifile,line) )
{
cout << line << '\n';
}
ifile.close();
}
else cout << "Unable to open file";
return 0;
}
相关文章推荐
- C++读写txt文件方式以及基于opencv的Mat数据类型读写txt文件类型
- C++读写txt文件
- c++ txt文件的读写及乱码问题解决
- C++文件读写操作(一)将字母表写入TXT文本文件
- 关于C++如何读写txt文件
- C++ 读写txt文件
- c++中 vs 简单的对txt文件读写
- C++读写txt文件
- C++ 结合 Boost:40行代码读写和处理 txt 文件
- C++读写txt文件方式以及基于opencv的Mat数据类型读写txt文件
- 打开指针C++文件读写操作(一)将字母表写入TXT文本文件
- C++中cout控制输出格式和读写txt文件
- 关于C和C++分别读写TXT数据文件的源代码
- C++ 读写txt文件
- C++中对txt文件的读写操作
- [C++]读写txt文件和从txt文件中读取数据写入数组中
- C++中对txt文件的读写操作
- C++中读写txt文件并分离字符
- C++读写txt文件(基本操作1)
- C++txt文件读写