posts - 21,  comments - 20,  trackbacks - 0
#include "stdafx.h"
#include 
<iostream>
#include 
<fstream>
#include 
<iterator>
#include 
<algorithm>
#include 
<vector>
#include 
<string>

using namespace std;

int main()
{
    ifstream in_file( 
"input_file.txt" );
    ofstream out_file( 
"output_file.txt" );
    
    
if ( ! in_file || ! out_file )
    
{
         cerr
<<"!!unable to open the necessary files.\n";
         
return -1;
    }

    
    istream_iterator
< string > is( in_file );
    istream_iterator
< string > eof;
    
    vector 
< string > text;
    copy( 
is, eof, back_inserter( text ));
    
    sort( text.begin(), text.end() );
    
    ostream_iterator
< string > os( out_file," " );
    copy( text.begin(), text.end(), os );
}
代码如上,是<<Essential C++>>中的一段
input_file的内容为"7 956 1 5 147 3 78 24 87 62 45 12 77 86 64 52 58 74"
执行后
output_file中内容为"1 12 147 24 3 45 5 52 58 62 64 7 74 77 78 86 87 956"

- -
sort()对字符串排序...shit...只认首字符
posted on 2008-07-19 12:36 Niino 阅读(166) 评论(0)  编辑 收藏 引用

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


<2008年7月>
293012345
6789101112
13141516171819
20212223242526
272829303112
3456789

常用链接

留言簿(2)

随笔档案

文章档案

搜索

  •  

最新评论

阅读排行榜

评论排行榜