使用迭代器打印set的成员 [英] Printing members of set using iterators

查看:69
本文介绍了使用迭代器打印set的成员的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个代码打印出字符串有些单词要解析为一组字符串,这几乎可以正常工作。它打印出字符串,但输出顺序不正确。有人看错了吗?





set< string> myset = parseStringToWords(一些要解析为一组字符串的单词);

set< string> :: iterator iter;

cout<< myset.size( )<< endl;

int i = 0;

for(iter = myset.begin(); iter!= myset.end(); ++ iter ){

cout<<(* iter)<< endl;

i + = 1;

cout<< i< < endl;

}

解决方案

容器集会自动对关键字进行排序,因此输出与输入顺序不同。 / BLOCKQUOTE>

I have this code to print out the string "Some words to parse to a set of strings", which almost works. It prints out the string, but not in the right order. Anyone see anything wrong?


set<string> myset = parseStringToWords("Some words to parse to a set of strings");
set<string>::iterator iter;
cout<<myset.size()<<endl;
int i=0;
for(iter=myset.begin(); iter!=myset.end();++iter){
cout<<(*iter)<<endl;
i+=1;
cout<<i<<endl;
}

解决方案

The container set would sort your keywords automatically, so the output is different from the input order.


这篇关于使用迭代器打印set的成员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆