Finding the letters within a word

closed account (367kGNh0)
As I'm sure you're aware, finding the length, first letter and last letter of a word is as simple as typing:

1
2
3
4
5
6
7
8
        string name;



	/*name.length() 
       OR 
        name.front() 
	name.back() */


but how do we find the letter within a word, such as the 2nd letter? Is there syntax for this?
Last edited on
Your question isn't quite clear.

If you want to find a substring within a string (even a character counts), then string::find() is convenient for that.
http://www.cplusplus.com/reference/string/string/find/

Or the contrary, if you want to know which character is present in a particular index of the string, then you can use indexes [] like you would with arrays.
1
2
string name = "John";
cout << name[0] // indexes start with 0 don't forget 
Topic archived. No new replies allowed.