首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

怎么逐行读取文本内容,然后根据关键字排序

2012-02-05 
如何逐行读取文本内容,然后根据关键字排序如:192.168.0.120192.168.0.230192.168.0.35右边的表示各个ip出

如何逐行读取文本内容,然后根据关键字排序
如:
192.168.0.1     20
192.168.0.2     30
192.168.0.3     5

右边的表示各个ip出现的次数
我想根据次数对文本进行重新的排列
谢谢

最好能附上点vc   的源码
非常感谢

[解决办法]
使用map即可
[解决办法]
ifstream ifs( "xxx ");
string ip;
int count;
multimap <int, string> m;
while (ifs > > ip > > count)
{
m.insert(make_pair(count, ip));
}
ifs.close();
ofstream ofs( "xxx ");
for (multimap <int, string> ::iterator iter = m.begin(); iter != m.end(); ++iter)
{
ofs < < iter-> second < < " " < < iter-> first < < "\n ";
}

热点排行