Having this:
#include <iostream> #include <vector> #include <string> using namespace std; struct Info{ string word; unsigned int i; }; vector<Info> unique(vector<Info> &vec){ vector<Info> ret; size_t len = vec.size(); for(int i=0; i<len; i++){ int j = 0; for(; j<len; j++){ if(vec[i].word == vec[j].word){ vec[i].i++; break; } } if(j>=len){ Info info{vec[i].word, 0}; ret.push_back(info); } } return ret; } int main(){ vector<Info> words, origs; string tmp; while(cin >> tmp){ Info info{tmp, 0}; words.push_back(info); } origs=unique(words); cout << "number of elements of vector: " << words.size() << ", of which are unique: "; for(int i=0; i<origs.size(); i++){ cout << origs[i].word << " "; } } Should gives unique elements of vector, but if I run it: foo.cpp:
a b c b c number of elements of vector: 5, of which are unique: No unique, values, that should be obtained by origs=unique(words);, and the result from above should be a b c. I am not sure, if break breaks only from the if block, or also from the inner for loop (which is intented). Can someone help?
breakbreaks the innermost loop, but the rest of your question is word salad; I can't tell what you're asking (and it seems to have nothing to do with the title).