Apr 30, 2013 at 6:18am UTC
How would you search through the a list of vectors? I have a upper case letter at the start of the lists and corresponding lower case letters in vectors how would I search through it to see how many times the corresponding lower case letter was repeated?
Apr 30, 2013 at 8:34am UTC
Your question is a bit vague.
Do you want to count the number of times a letter occurs in a vector of chars?
If so, try the count reference page:
http://www.cplusplus.com/reference/algorithm/count/
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
std::vector<char > myvector ();
myvector.push_back( 'a' );
myvector.push_back( 'b' );
myvector.push_back( 'c' );
myvector.push_back( 'b' );
myvector.push_back( 'a' );
myvector.push_back( 'a' );
int mycount;
mycount = std::count (myvector.begin(), myvector.end(), 'a' );
std::cout << "Lower case a appears " << mycount << " times.\n" ;
mycount = std::count (myvector.begin(), myvector.end(), 'b' );
std::cout << "Lower case b appears " << mycount << " times.\n" ;
mycount = std::count (myvector.begin(), myvector.end(), 'c' );
std::cout << "Lower case c appears " << mycount << " times.\n" ;
If that's not what you're after, try posting the data structure you're looking through, and the output you want.
Last edited on Apr 30, 2013 at 8:35am UTC