返回列表 發帖

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

本帖最後由 tonyh 於 2016-7-16 11:23 編輯

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

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

返回列表