How to alter Chars within Strings with Vectors

Hello,

I would like some help figuring out how to take a vector of strings, and manipulate the letters of each individual string. Ex:

vector<string> names; <-- my vector

After using a for loop to fill the vector up with some names, I then want to use another loop to take each individual name, and go through each individual letter of each individual name and check for proper grammar. For example, making sure the first letter of every name is capitalized.

With a single string I would normally do this:

string name;
cin >> name;
toupper(name[0]);

The dilemma I run into with the vectors is that names[0] calls that particular element of the vector instead of the first letter of the string. I guess my question is...

How do I access both a specific string within the vector and also a specific character within that string?

Thank you
Iterate over vector:
for (vector<string>::iterator itr = names.begin(); itr != names.end(); ++itr)
{
//Now you have a string in each *itr
string nm = *itr;
//Now, do as you want with this string, and assign it back to *itr
toupper(nm[0]);

*itr = nm;
}



See below for reference:

http://www.kgsepg.com/project-id/12876-embracing-stl
http://www.kgsepg.com/project-id/12877-stl-containers

~Gorav
Thank you Gorav.
Topic archived. No new replies allowed.