Board logo

標題: 宣告字串 (二) [打印本頁]

作者: tonyh    時間: 2013-10-12 17:09     標題: 宣告字串 (二)

兩種方式:
1. 字元陣列
2. 字串變數
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     char str1[]="My name is Tony!";   
  7.     string str2="I come from Taiwan!";
  8.     cout<<str1<<endl;
  9.     cout<<str2<<endl;
  10.     system("pause");
  11.     return 0;
  12. }
複製代碼

作者: 施伯叡    時間: 2013-10-12 17:11

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     char str1 [] = "My name is boray";
  7.     string str2 = "I come from Taiwan";
  8.     cout << str1 <<endl;
  9.     cout << str2 <<endl;
  10.    
  11.     system("pause");
  12.     return 0;
  13. }
複製代碼

作者: 張峻瑋    時間: 2013-10-12 17:13

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.    
  7.     char str1[]="my name is 張峻瑋!!";
  8.     string str2="I come from Taiwan!!";
  9.     cout<<str1<<endl;
  10.     cout<<str2<<endl;
  11. system ("pause");
  12. return 0;   
  13.    
  14. }
複製代碼

作者: 張彥承    時間: 2013-10-12 17:14

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main ()
  5. {
  6. char str1[]="My name is Kevin.Legend.Knight";
  7. string str2="I come from Taiwan";
  8. cout<<str1<<endl;
  9. cout<<str2<<endl;   
  10. system("pause");
  11. return 0;   
  12. }
複製代碼

作者: 張郁偵    時間: 2013-10-12 17:16

  1. #include <iostream>
  2. #include <cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.    char str1 [] =  "My name is Jennifer  !";
  7.   string str2  =  "I come from Taiwan!";

  8.    cout << str1  << endl;
  9.    cout << str2 << endl;
  10.    system ("pause");
  11.    return 0;   
  12. }
複製代碼

作者: 周雍程    時間: 2013-10-12 17:17

  1. #include <iostream>
  2. #include <cstdlib>
  3. using namespace std;

  4. int main()
  5. {
  6.     char str1[] = "my name is David !";
  7.     string str2 = "I come from Taiwan !";
  8.     cout<< str1 << endl;  
  9.     cout<< str2 << endl;
  10.     system("pause");
  11.     return 0;
  12. }
複製代碼

作者: 張郁庭    時間: 2013-10-12 17:18

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;

  4. int main ()
  5. {
  6.       
  7.       char str1 [] = "Myname is Chang yu Ting!";
  8.       string str2 = "I come from Taiwan!";
  9.       cout << str1 << endl;
  10.       cout << str2 << endl;
  11.     system ("pause");
  12.     return 0;
  13. }
複製代碼





歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://istak.org.tw/seed/) Powered by Discuz! 7.2