码迷,mamicode.com
首页 > 其他好文 > 详细

1_7

时间:2014-05-13 17:27:36      阅读:234      评论:0      收藏:0      [点我收藏+]

标签:des   blog   class   code   c   ext   

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
///////////////////////////////////////////////////////////
// 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;
}

  

1_7,布布扣,bubuko.com

1_7

标签:des   blog   class   code   c   ext   

原文地址:http://www.cnblogs.com/yangtze736-2013-3-6/p/3724531.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!