Nov 6, 2014 at 8:30am Nov 6, 2014 at 8:30am UTC
Hello,
i'm trying to get a vector element index in a vector of string, but i get weird results. Could someone explain the best and the fastest method to use?
1 2 3 4 5
for (long index=0; index<(long )words.size(); ++index) {
if (words.at(index)=="Hello" ) {
cout << "Word at index: " << index << endl;
}
}
Last edited on Nov 6, 2014 at 8:30am Nov 6, 2014 at 8:30am UTC
Nov 6, 2014 at 8:33am Nov 6, 2014 at 8:33am UTC
What do you mean by weird results? What output do you get and what output do you expect?
Nov 6, 2014 at 8:40am Nov 6, 2014 at 8:40am UTC
Thank you for the reply.
I expect that the word i'm looking for is at position 1,2,3....
but i get 234345235 or similar strange number
Nov 6, 2014 at 8:50am Nov 6, 2014 at 8:50am UTC
I don't think the problem is in the code you have posted. Could you post a real code example of a program that reproduces this problem?
Nov 6, 2014 at 8:50am Nov 6, 2014 at 8:50am UTC
Last edited on Nov 6, 2014 at 8:52am Nov 6, 2014 at 8:52am UTC
Nov 6, 2014 at 9:16am Nov 6, 2014 at 9:16am UTC
Find my error:
i was using a wrong vector with similar name.
Shame on me.
The old code works well.