返回列表 發帖

基本輸入輸出


cout 輸出<-------->cin 輸入
cout<<x; 輸出x
cin>>x; 輸入x
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int a;   //int ---> integer  整數
  7.     cout<<"請輸入一整數: ";
  8.     cin>>a;
  9.     cout<<"你剛輸入的數字是: "<<a<<endl;
  10.     system("pause");
  11.     return 0;   
  12. }
複製代碼

  1. #include<iostream>

  2. using namespace std;

  3. int main(){
  4.         //整數 int 10,50,100..
  5.         //浮點數(小數) float 3.14...
  6.         //字元 char 'a','b','@'
  7.         //字串 string "abcdefg","apple"
  8.        
  9.         //宣告變數(盒子)
  10.         //變數型態 變數名字=賦予值

  11.         int a=50;
  12.        
  13.         //cout輸出 <<串接符號(當方法、變數、字串要一起使用) endl換行
  14.        
  15.         cout<<"a原本是:"<<a<<endl;       
  16.         cout<<"請輸入數字:";
  17.         //cin輸入 >>(指向我要輸入的盒子)
  18.         cin>>a;
  19.         cout<<"a輸入後是:"<<a<<endl;

  20.         system("pause");
  21.         return 0;
  22. }
複製代碼

TOP

返回列表