返回列表 發帖

陣列 (三) - 字元陣列與字串 2

本帖最後由 tonyh 於 2019-9-3 16:32 編輯

試利用字元陣列宣告字串, 並用for迴圈將字元一個個帶出來, 如下圖所示.


本帖隱藏的內容需要回復才可以瀏覽

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {      
  6.     char strc[]={"Hello!My name is Tony!"};
  7.     for(int i=0;i<=21; i++)
  8.     {
  9.         cout<<strc[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 strc[]={"Hello!My name is Tony!"};
  7.     for(int i=0; i<=21; i++)
  8.     cout<<strc[i];
  9.     system("pause");
  10.     return 0;   
  11. }
複製代碼

TOP

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

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {      
  6.     char strc[]="Hello!My name is Tony!";
  7.     for(int i=0; i<=21; i++)
  8.         cout<<strc[i];
  9.     system("pause");
  10.     return 0;   
  11. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {     
  6.     char strc[]="Hello!My name is Tony";
  7.     for(int i=0; i<=21; i++)
  8.     cout<<strc[i];
  9.     system("pause");
  10.     return 0;   
  11. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {      
  6.     char strc[]="Hello!My name is Tony!";
  7.     for(int i=0; i<=21; i++)
  8.         cout<<strc[i];
  9.     system("pause");
  10.     return 0;   
  11. }
複製代碼

TOP

返回列表