返回列表 發帖

陣列 (三) - 宣告字串 2

  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. }
複製代碼

本帖最後由 陳品肇 於 2019-1-26 14:30 編輯
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     char a[7]="cheney";
  7.     char b[6]={'c','h','e','n','e','y'};
  8.     string c[2]={"che","ney"};
  9.     string d="cheney";
  10.     int e=3;
  11.     char f='p';
  12.    
  13.     cout<<a<<endl;
  14.     for(int i=0;i<=5;i++)
  15.     {cout<<b[i];
  16.     }
  17.     cout<<endl;
  18.     cout<<c[0]<<c[1]<<endl;
  19.     cout<<d<<endl;
  20.     cout<<e<<endl;
  21.     cout<<f<<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 a1[4]="abc";
  7.     char a2[3]={'a','b','c'};
  8.     string b1="abc";
  9.     string b2[2]={"ab","c"};
  10.     int a=1;
  11.     char c='x';
  12.     cout<<a1<<endl;
  13.     for(int i=0;i<=3;i++)
  14.     {
  15.         cout<<a2[i];        
  16.     }
  17.     cout<<endl;
  18.     cout<<b1<<endl;
  19.     for(int i=0;i<3;i++)
  20.     {
  21.         cout<<b2[i];        
  22.     }
  23.     cout<<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 a1[10]="Minecraft";
  7.     char a2[9]={'M','i','n','e','c','r','a','f','t'};
  8.     string b1[2]={"Mine","craft"};
  9.     string b2="Minecraft";
  10.     int c1=1;
  11.     char c2='2';
  12.     cout<<a1<<endl;
  13.     for(int i=0;i<9;i++)
  14.     {
  15.          cout<<a2[i];   
  16.     }
  17.     cout<<endl;
  18.     for(int i=0;i<2;i++)
  19.     {
  20.          cout<<b1[i];   
  21.     }
  22.     cout<<endl;
  23.     cout<<b2<<endl;
  24.     cout<<c1<<endl;
  25.     cout<<c2<<endl;
  26.       
  27.     system("pause");
  28.     return 0;   
  29. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     char j1[7]="edward";
  7.     char j2[7]={'e','d','w','a','r','d'};
  8.     string j3[3]={"ed","wa","rd"};
  9.     string j4="edward";
  10.     int i=3;
  11.     char c='p';
  12.     cout<<j1<<endl;
  13.    
  14.     for(int i=0; i<3; i++)
  15.        cout<<j3[i]<<endl;
  16.       
  17.     cout<<endl;
  18.    
  19.     cout<<j4<<endl;
  20.     cout<<c<<endl;
  21.     system("pause");
  22.     return 0;
  23. }  
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     char f[5]="章魚";
  7.     cout<<f<<endl;
  8.     char f1[5]={'S','a','b','e','r'};
  9.     for(int i=0;i<5;i++)
  10.     {
  11.             cout<<f1[i];
  12.     }
  13.     cout<<endl;
  14.     char y='I';
  15.     cout<<y<<endl;
  16.    
  17.     string g[5]={"A","r","t","h","ur"};
  18.     for(int i=0;i<5;i++)
  19.     {
  20.             cout<<g[i];
  21.     }
  22.     cout<<endl;
  23.     string g1="Arthur";
  24.     cout<<g1<<endl;
  25.    
  26.     int x=16;
  27.     cout<<x<<endl;
  28.     int x1[3]={1,2,3};
  29.     for(int i=0;i<3;i++)
  30.     {
  31.             cout<<x1[i]<<endl;
  32.     }
  33.    
  34.    
  35.     system("pause");
  36.     return 0;
  37. }
複製代碼
回復 1# 陳品肇

TOP

返回列表