cpp:homework:hw3answer
國立屏東大學 資訊工程系 物件導向程式設計
hw1-3 參考解答
using namespace std;
#include <iostream>
#include <cstring>
int main()
{
string str;
cout << "Please input a string: " ;
getline(cin,str);
cout << "Capitalizing..."<< endl;
if(str[0] < 'A' || str[0] > 'Z')
{
str[0]=toupper(str[0]);//toupper可直接小寫轉大寫
}
for(int i=1; str[i]!= '\0';i++)
{
if(str[i] == ' ')
{
i++;
if(str[i] < 'A' || str[i] > 'Z')
str[i]=toupper(str[i]);
}
}
cout << "Output: " << str << endl;
}
cpp/homework/hw3answer.txt · 上一次變更: 2019/07/02 15:01 (外部編輯)
