///////////////////////////////////////////////////////////
// Copyright (c) 2013, ShangHai xxxx Inc.
//
// FileName: 1_7.cpp
//
// Description:
//
// Created: 2014年05月12日 星期一 22时39分27秒
// Revision: Revision: 1.0
// Compiler: g++
//
///////////////////////////////////////////////////////////
#include <iostream>
#include <fstream>
#include <algorithm>
#include <string>
#include <vector>
using
namespace std;
int
main()
{
ifstream in_file( "./test.txt" );
if ( !in_file )
{
cerr<< "oops! unable to open input file\n" ;
return
-1;
}
ofstream out_file( "./test.sort" );
if ( !out_file )
{
cerr<< "oops! unable to open output file\n" ;
return
-2;
}
string word;
vector<string> text;
while (in_file >> word)
{
text.push_back(word);
}
cout<< "unsorted text: \n" ;
for ( int
ix = 0; ix < text.size(); ++ix)
{
cout<<text[ix]<< ‘ ‘ ;
}
cout << endl;
sort(text.begin(), text.end());
out_file << "sorted text: \n" ;
for ( int
ix = 0; ix < text.size(); ++ix)
{
out_file << text[ix] << ‘ ‘ ;
}
out_file << endl;
return
0;
}
|