15,440
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
#include <string>
#include <sstream>
#include <cctype>
using namespace std;
int main()
{
string line, word;
while(getline(cin, line))
{
istringstream stream(line);
while(stream >> word)
{
for(string::iterator iter= word.begin(); iter != word.end(); ++iter)
{
if(isalpha(*iter) && iter == word.begin())//判断每个空格后的第一个字符是不是字母,如果是的话,执行if语句
{
*iter = toupper(*iter);//将每个单词的首字母大写
}
else if(isalpha(*iter))
{
*iter = tolower(*iter);
}
}
cout << word << " ";
}
}
cout << endl;
return 0;
}