文件的输入输出和排序.txt

来自「其中一部分是自己写得,一部分是摘录的,希望站长能批准,我以后一定多多努力上传!」· 文本 代码 · 共 30 行

TXT
30
字号
#include <iostream>
#include <fstream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
int main()
{
ifstream in_file( "C:\\My Documents\\text.txt" );
if ( ! in_file )
{ cerr << "oops! unable to open input file\n"; return -1; }
ofstream out_file("C:\\My Documents\\text.sort" );
if ( ! out_file )
{ cerr << "oops! unable to open input file\n"; return -2; }
string word;
vector< string > text;
while ( in_file >> word )
text.push_back( word );
int ix;
cout << "unsorted text: \n";
for ( ix = 0; ix < text.size(); ++ix )
cout << text[ ix ] << ' ';
cout << endl;
sort( text.begin(), text.end() );
out_file << "sorted text: \n";
for ( ix = 0; ix < text.size(); ++ix )
out_file << text[ ix ] << ' ';
out_file << endl;
return 0;
} 

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?