STL-string用法
1 #include <string> 2 #include <iostream> 3 #include <cstring> 4 #include <algorithm> 5 6 using namespace std; 7 8 int to_lower(int c) 9 { 10 if (isupper(c)) 11 { 12 return (c+32); 13 } 14 15 return c; 16 } 17 18 int to_upper(int c) 19 { 20 if(isupper(c)) 21 { 22 return (c-32); 23 } 24 return c; 25 } 26 27 int main() 28 { 29 // 初始化string 30 string s1="ACM"; 31 32 string s2("ACM"); 33 34 string s3=s2; 35 36 //string s4(10,"ACM"); 37 string s4(10,'A'); 38 // 第四种初始化方式,只能初始化单个字符 39 40 cout<<s1<<endl; 41 cout<<s2<<endl; 42 cout<<s3<<endl; 43 cout<<s4<<endl; 44 45 46 cout<<"数组方式遍历:"<<endl; 47 //