纯c++读写文件方式
2007-09-30 17:03
399 查看
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
#include "stdafx.h"
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
#include<iostream>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
#include<vector>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
#include<algorithm>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
#include<fstream>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
#include<string>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using namespace std;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
int _tmain(int argc, _TCHAR* argv[])
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
ifstream infile("ReadMe.txt");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
ofstream sortfile("sort.txt");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
string tempstring;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
vector<string> v;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if(!infile||!sortfile)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
cerr<<"error while open file";
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return -1;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
while(infile>>tempstring) v.push_back(tempstring); //reading.......
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
sort(v.begin(),v.end());
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
for(int i=0;i<v.size();i++)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
cout<<v[i]<<" ";
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
sortfile<<v[i]<<" ";
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return 0;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
相关文章推荐
- C++读写txt文件方式以及基于opencv的Mat数据类型读写txt文件类型
- C++读写EXCEL文件方式比较
- C/c++文件的读写方式
- C++读写EXCEL文件方式比较
- C++文件读写 打开方式等比较全
- C++读写EXCEL文件方式比较
- C++读写EXCEL文件方式比较
- C++文件读写(打开方式等)
- C++读写EXCEL文件方式比较
- C++文件读写 打开方式等比较全
- C++读写txt文件方式以及基于opencv的Mat数据类型读写txt文件
- C++读写EXCEL文件方式比较 .
- C/C++读写excel文件 的几种方式
- C++读写EXCEL文件方式比较
- C++文件读写 打开方式等比较全
- C++读写Excel文件方式比较
- C++读写EXCEL文件方式比较
- C++读写EXCEL文件方式比较
- C++读写EXCEL文件方式比较
- 四种读写文件的方式:系统调用(open/read/write),C语言(fopen,fgets, fputs),C++(ifstream, ofstream getline,)泛型算法