文件读写 fstream
2016-12-26 09:57
148 查看
读文件
char buffer[256];
ifstream in("words.txt");
if (!in.is_open())
{ cout << "Error opening file"; exit (1); }
while (!in.eof())
{
in.getline(buffer,100);
cout << buffer << "1"<< endl;
if( in.good() ) //这句话防止被再读一次
{
break;
}
}
in.close();
写文件
ofstream outfile;
outfile.open("words.txt");
cout<<"writing: "<<s<<endl;
outfile<<s<<endl;
outfile.close();
char buffer[256];
ifstream in("words.txt");
if (!in.is_open())
{ cout << "Error opening file"; exit (1); }
while (!in.eof())
{
in.getline(buffer,100);
cout << buffer << "1"<< endl;
if( in.good() ) //这句话防止被再读一次
{
break;
}
}
in.close();
写文件
ofstream outfile;
outfile.open("words.txt");
cout<<"writing: "<<s<<endl;
outfile<<s<<endl;
outfile.close();
相关文章推荐
- 20110327-8.1-fstream定义读写已命名文件的类型
- 用C++中STL提供的fstream和stream_iterator读写二进制文件。
- fstream读写创建可能不存在的文件
- C++文件读写详解(ofstream,ifstream,fstream)
- C++文件读写详解(ofstream,ifstream,fstream)
- 利用fstream 读写二进制文件
- C++文件读写详解(ofstream,ifstream,fstream)
- C++文件读写详解(ofstream,ifstream,fstream)
- C++文件读写详解(ofstream,ifstream,fstream)
- 文件读写操作之二 <文本文件操作> fstream
- ios::binary和ios::text打开文件区别,fstream读写文件示例
- fstream读写二进制文件
- fstream提供了三个类,用来实现c++对文件的操作。(文件的创建、读、写)。 ifstream -- 从已有的文件读 ofstream -- 向文件写内容 fstream - 打开文件供读写
- C++利用fstream读写文件
- 读写文件(fstream)
- vc文件读写,用fstream和CStdioFile
- fstream与 C 风格(例如fread 和 fwrite )两种读写文件方法的效率比较
- 使用fstream,ifstream,ofstream读写文件的一种情形
- 【转】C++文件读写详解(ofstream,ifstream,fstream)
- C++文件读写详解(ofstream,ifstream,fstream)