读书人

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

发布时间: 2012-02-05 12:07:14 作者: rapoo

如何逐行读取文本内容,然后根据关键字排序
如:
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 ";
}

读书人网 >C++

热点推荐