返回列表 發帖

陣列 (四) - 宣告字串 2

本帖最後由 tonyh 於 2022-1-22 10:58 編輯
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     char n1[5]="Tony";   //字元陣列
  7.     char n2[4]={'T','o','n','y'};  //字元陣列
  8.     string n3[2]={"To","ny"};    //字串陣列
  9.     string n4="Tony";   //字串型態的變數
  10.     int a=3;       //整數型態的變數
  11.     char c='P';    //字元型態的變數
  12.     cout<<n1<<endl;  //輸出n1     
  13.     for(int i=0; i<4; i++)  //輸出n2
  14.         cout<<n2[i];
  15.     cout<<endl;
  16.     for(int i=0; i<2; i++)  //輸出n3
  17.         cout<<n3[i];
  18.     cout<<endl;
  19.     cout<<n4<<endl;  //輸出n4
  20.     cout<<a<<endl;   //輸出a
  21.     cout<<c<<endl;   //輸出c
  22.     system("pause");
  23.     return 0;   
  24. }
複製代碼

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     char n1[5]="Tony";   
  7.     char n2[4]={'T','o','n','y'};
  8.     string n3[2]={"To","ny"};   
  9.     string n4="Tony";   
  10.     int a=3;     
  11.     char c='P';   
  12.     cout<<n1<<endl;      
  13.     for(int i=0; i<4; i++)  
  14.         cout<<n2[i];
  15.     cout<<endl;
  16.     for(int i=0; i<2; i++)  
  17.         cout<<n3[i];
  18.     cout<<endl;
  19.     cout<<n4<<endl;
  20.     cout<<a<<endl;
  21.     cout<<c<<endl;   
  22.     system("pause");
  23.     return 0;   
  24. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     char n1[5]="Tony";
  7.     char n2[4]={'T','o','n','y'};
  8.     string n3[2]={"To","ny"};
  9.     string n4="Tony";
  10.     int a=3;
  11.     char c='P';
  12.     cout<<n1<<endl;
  13.     for(int i=0;i<4;i++)
  14.     cout<<n2[i];
  15.     cout<<endl;
  16.     for(int i=0;i<2;i++)
  17.     cout<<n3[i];
  18.     cout<<endl;
  19.     cout<<n4<<endl;
  20.     cout<<a<<endl;     
  21.     cout<<c<<endl;   
  22.     system("pause");
  23.     return 0;   
  24. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     char n1[5]="Tony";
  7.     char n2[4]={'T','o','n','y'};
  8.     string n3[2]={"To","ny"};
  9.     string n4="Tony";
  10.     char c='P';
  11.     cout<<n1<<endl;
  12.     for(int i=0;i<4;i++)
  13.     {
  14.         cout<<n2[i];
  15.     }cout<<endl;
  16.     for(int i=0;i<2;i++)
  17.     {
  18.         cout<<n3[i];
  19.     }cout<<endl;
  20.     cout<<n4<<endl;
  21.     cout<<c<<endl;
  22.     system("pause");
  23.     return 0;   
  24. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     char n1[5]="tony";
  7.     char n2[4]={'t','o','n','y'};
  8.     string n3[2]={"to","ny"};
  9.     string n4="tony";
  10.     int a=3;
  11.     char c='p';
  12.     cout<<n1<<endl;
  13.     for(int i=0;i<4;i++)
  14.     cout<<n2[i];
  15.     cout<<endl;
  16.     for(int i=0;i<2;i++)
  17.     cout<<n3[i];
  18.     cout<<endl;
  19.     cout<<n4<<endl;
  20.     cout<<a<<endl;
  21.     cout<<c<<endl;
  22.    
  23. system("pause");   
  24. return 0;   
  25. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {   
  6.     char c='P';
  7.     cout<<c<<endl;
  8.     system("pause");
  9.     return 0;   
  10. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     char n1[5]="Tony";   
  7.     char n2[4]={'T','o','n','y'};  
  8.        string n3[2]={"To","ny"};   
  9.     string n4="Tony";   
  10.     int a=3;      
  11.     char c='P';   
  12.     cout<<n1<<endl;     
  13.     for(int i=0; i<4; i++)  
  14.         cout<<n2[i];
  15.     cout<<endl;
  16.     for(int i=0; i<2; i++)  
  17.         cout<<n3[i];
  18.     cout<<endl;
  19.     cout<<n4<<endl;  
  20.     cout<<a<<endl;   
  21.     cout<<c<<endl;   
  22.     system("pause");
  23.     return 0;   
  24. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     char n1[5]="tony";
  7.    
  8.     char n2[4]={'t','o','n','y'};
  9.    
  10.     string n3[2]={"to","ny"};
  11.    
  12.     string n4="tony";
  13.    
  14.     cout<<n1<<endl;
  15.     for(int i=0;i<4;i++)
  16.     {
  17.        cout<<n2[i];               
  18.     }
  19.     cout<<endl;
  20.     for(int i=0;i<2;i++)
  21.     {
  22.        cout<<n3[i];               
  23.     }
  24.     cout<<endl;
  25.     cout<<n4<<endl;
  26.     system("pause");
  27.     return 0;   
  28. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     char n1[5]="tony";
  7.     cout<<n1<<endl;
  8.     char n2[4]={'t','o','n','y'};
  9.     for(int i=0;i<4;i++)
  10.     cout<<n2[i];
  11.     cout<<endl;
  12.     string n3[2]={"to","ny"};
  13.     for(int i=0;i<2;i++)
  14.     cout<<n3[i];
  15.     cout<<endl;
  16.     string n4="tony";
  17.     cout<<n4<<endl;
  18.     system("pause");
  19.     return 0;   
  20. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     char n1[5]="Tony";
  7.     char n2[4]={'T','o','n','y'};
  8.     string n3[2]={"To","ny"};
  9.     string n4="Tony";
  10.     cout<<n1<<endl;
  11.     for(int i=0;i<4;i++)
  12.         cout<<n2[i];
  13.     cout<<endl;
  14.     for(int i=0;i<2;i++)
  15.         cout<<n3[i];
  16.     cout<<endl;
  17.     cout<<n4<<endl;
  18.     system("pause");
  19.     return 0;
  20. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     char n1[5]="Tony";
  7.     char n2[4]={'T','o','n','y'};
  8.     char  c='P';
  9.     string n4="Tony";
  10.     string n5[2]={"To","ny"};
  11.     int a=3;
  12.     cout<<n1<<endl;
  13.     for(int i=0;i<4;i++)
  14.     {
  15.         cout<<n2[i];        
  16.     }
  17.     cout<<endl;
  18.     for(int i=0;i<2;i++)
  19.     {
  20.         cout<<n5[i];        
  21.     }
  22.     cout<<endl;
  23.     cout<<n4<<endl;
  24.     cout<<a<<endl;
  25.     cout<<c<<endl;
  26.     system("pause");
  27.     return 0;   
  28. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     char n1[5]="Tony";   
  7.     char n2[4]={'T','o','n','y'};
  8.     string n3[2]={"To","ny"};
  9.     string n4="Tony";
  10.     int a=3;
  11.     char c='P';
  12.     cout<<n1<<endl;   
  13.     for(int i=0; i<4; i++)
  14.         cout<<n2[i];
  15.     cout<<endl;
  16.     for(int i=0; i<2; i++)
  17.         cout<<n3[i];
  18.     cout<<endl;
  19.     cout<<n4<<endl;
  20.     cout<<a<<endl;
  21.     cout<<c<<endl;
  22.     system("pause");
  23.     return 0;   
  24. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     char n1[5]="Tony";
  7.     char n2[4]={'T','o','n','y'};
  8.     string n3[2]={"To","ny"};
  9.     string n4="Tony";
  10.     int a=3;
  11.     char c='P';
  12.     cout<<n1<<endl;
  13.     for(int i=0; i<2; i++)
  14.         cout<<n3[i];
  15.         cout<<endl;
  16.     cout<<n4<<endl;
  17.     cout<<a<<endl;
  18.     cout<<c<<endl;
  19.     system("pause");
  20.     return 0;   
  21. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {   
  6.     int a=3;
  7.     cout<<a<<endl;
  8.     system("pause");
  9.     return 0;   
  10. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {   
  6.     string n4="Tony";
  7.     cout<<n4<<endl;
  8.     system("pause");
  9.     return 0;   
  10. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     char n1[5]="Tony";
  7.     char n2[4]={'T','o','n','y' }
  8.     string n3[2]={"To","ny"};   
  9.     string n4="Tony";
  10.      int a=3;      
  11.     char c='P';   
  12.     cout<<n1<<endl;      
  13.     for(int i=0; i<4; i++)
  14.         cout<<n2[i];
  15.         cout<<endl;
  16.     for(int i=0; i<2; i++)
  17.         cout<<n3[i];
  18.     cout<<endl;
  19.     cout<<n4<<endl;  
  20.     cout<<a<<endl;   
  21.     cout<<c<<endl;
  22.     system("pause");
  23.     return 0;
  24. }      
複製代碼

TOP

本帖最後由 高昀昊 於 2022-1-15 10:47 編輯
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {   
  6.     string n3[2]={"To","ny"};
  7.     for(int i=0; i<2; i++)
  8.     {   
  9.         cout<<n3[i];
  10.     }
  11.     cout<<endl;
  12.     system("pause");
  13.     return 0;   
  14. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {   
  6.     char n2[4]={'T','o','n','y'};
  7.     for(int i=0; i<4; i++)
  8.     {
  9.         cout<<n2[i];
  10.     }
  11.     cout<<endl;
  12.     system("pause");
  13.     return 0;   
  14. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {   
  6.     char n1[5]="Tony";
  7.     cout<<n1<<endl;
  8.     system("pause");
  9.     return 0;   
  10. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     char n1[5]="Tony";  
  7.     int a=3;         
  8.     cout<<n1<<endl;  
  9.     for(int i=0; i<4; i++)
  10.     cout<<endl;  
  11.     system("pause");
  12.     return 0;   
  13. }
複製代碼

TOP

返回列表