返回列表 發帖

宣告字串 (二)

兩種方式:
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. }
複製代碼

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

TOP

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

TOP

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

TOP

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

TOP

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

TOP

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

TOP

返回列表