sort.cpp

来自「包含C++中map」· C++ 代码 · 共 43 行

CPP
43
字号
#include<iostream>
#include<vector>
#include<string>
#include<fstream>
#include<algorithm>

using namespace std;

int main()
{
	ifstream infile("e:\\vc++\\text.txt");
	if(! infile)
		cerr << "Oops, Unable to open input file! "<< endl;

	ofstream outfile("e:\\vc++\\text.sort");
	if(! outfile)
		cerr << "Oops,Unable to open output file! "<< endl;

	string word;
	vector<string> text;
	while(infile >> word)
	{
		text.push_back(word);
	}

	int ix;
	cout << "Unsorted text: " << endl;

	for(ix=0;ix<text.size();++ix)
		cout << text[ix] << "  ";

	cout << endl;

	sort(text.begin (),text.end());

	outfile << "The sorted text: \n ";

	for (ix=0;ix<text.size();++ix)
		outfile << text[ix]<< "  ";
    outfile << endl;

	return 0;
}

⌨️ 快捷键说明

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