給定一個字符串,將其中全部的小寫字母轉換成大寫字母。ios
helloworld123Ha
HELLOWORLD123HA
1 #include <iostream> 2 #include <string> 3 using namespace std; 4 int main() 5 { 6 string s; 7 //cin>>s;//不能存入空格 8 getline(cin,s); 9 for (int i=0;i<s.length();++i) 10 { 11 if (s[i]>='a'&&s[i]<='z') 12 { 13 s[i] = s[i] - 32; 14 } 15 } 16 cout << s; 17 return 0; 18 }
1 #include <iostream> 2 #include <iomanip> 3 #include <cstring> 4 using namespace std; 5 int main() 6 { 7 char str[100]; 8 int i, len; 9 gets_s(str); 10 len = strlen(str); 11 for (i = 0; i < len; i++) { 12 if (str[i] >= 'a' && str[i] <= 'z') { 13 str[i] += 'A' - 'a'; 14 } 15 } 16 cout << str; 17 return 0; 18 }