• Post Reply Bookmark Topic Watch Topic
  • New Topic

about element of vector  RSS feed

 
qingwu wang
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

if *s is in the vector *v,how can I sure the index of s element in the vector *v.
vector element: "a","b","c","Iamin","d","f".
I want to get the position of "Iamin",if there are concrete function,that will be good!
 
S Sharma
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
U can do that with the indexOf method...
The return type is an integer, giving u the 'first' occurence of the object.
If 'v' is yr vector and 's' is the string u want to look for-
int i=0;
i = v.indexOf(s);
i is yr index....
If the object is not found, -1 is returned
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!