迭代器的几种遍历输出方式
 #include<vector>
#include<string>
#include<iostream>
using namespace std;
int main(){
vector<string> text;
string word;
while (getline(cin, word)){//循环读入字符串至vector<string>中,以trl+z回车结束
text.push_back(word);
}
//下标迭代方式输出
cout << "下标迭代方式输出" << endl;
for (vector<string>::size_type ix = 0; ix != text.size(); ++ix)
cout << text[ix] << endl;
//迭代器方式输出
cout << "迭代器方式输出" << endl;
for (vector<string>::iterator it = text.begin(); it != text.end(); it++){
cout << *it << endl;
}
//int result = uniqueMorseRepresentations(text);
//精简迭代方式输出
cout << "精简迭代方式输出" << endl;
for (const string& words : text){
cout << words << endl;
}
getchar();
return 1;
}
                    
                
                
            
        
浙公网安备 33010602011771号