使用迭代器打印set的成员 [英] Printing members of set using iterators
问题描述
我有这个代码打印出字符串有些单词要解析为一组字符串,这几乎可以正常工作。它打印出字符串,但输出顺序不正确。有人看错了吗?
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屋!