C++ primer 5.3.2练习
实现用string保存读取的字符序列
计算元音字母数量、空格数量以及换行符数量。
#include <iostream>
#include <string>
int main()
{
using namespace std;
string s;
int vowerCount = 0, newlineCount = 0, blankCount = 0;
cout << "Enter something: " << endl;
while(getline(cin, s)){
for (string::iterator it = s.begin(); it != s.end(); ++it){
if (*it == 'a' || *it == 'e' || *it == 'i' || *it == 'o' || *it == 'u')
++vowerCount;
else if(*it == ' ')
++blankCount;
}
++newlineCount;
}
cout << "There are " << vowerCount << " vowels, " << '\n'
<< newlineCount << "newlines, " << '\n'
<< blankCount << " blanks, " << endl;
system("Pause");
return 0;
}