Counting number of vowels in a string

Pages: 12
using STL
1
2
string str("SHADOWCODE");
transform(str.begin(), str.end(), str.begin(), tolower);

or
1
2
3
string str("SHADOWCODE");
for(int i = 0; i < str.length(); i++)
    str.at(i) = tolower(str.at(i));
Yes you could, but, hmm..

 
if (text[c] == 'a' || text[c] == 'A')


Maybe, you could read this. Making code that is robust is much easier to mantain.

http://www.cplusplus.com/reference/locale/tolower/
Topic archived. No new replies allowed.
Pages: 12