返回列表 發帖

基本輸入輸出


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>     //引入 <基本輸入輸出> 標頭檔 input & output stream
  2. #include<cstdlib>      //引入 <標準函式庫> 標頭檔 c standard library
  3. using namespace std;   //指定命名空間為 std
  4. int main()    //主函式
  5. {
  6.     //你要做的事
  7.     string name="蔡沛倢",school="過埤國小",like="彈吉他,跳舞,睡覺,睡覺,再睡覺";
  8.     int age=11;
  9.     float h=146.7, w=39.9;
  10.     cout<<"我的名字: "<<name<<endl;  
  11.     cout<<"就讀: "<<school<<endl;
  12.     cout<<"今年: "<<age<<" 歲"<<endl;
  13.     cout<<"身高: "<<h<<" 公分"<<endl;
  14.     cout<<"體重: "<<w<<" 公斤"<<endl;
  15.     cout<<"興趣: "<<like<<"^^"<<endl;
  16.     int a;
  17.     cout<<"請輸入密碼:"<<a<<endl;
  18.     cin>>a;
  19.     cout<<"已解鎖"<<a<<endl;
  20.     system("pause");       //讓畫面暫停
  21.     return 0;              //回傳0到主控台,告知該程式已成功執行
  22. }
複製代碼

TOP

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

TOP

  1. #include<iostream>
  2. using namespace std;
  3. int main(){
  4.     int a=1;
  5.     cout<<"a本來是:"<<a<<endl;
  6.     cout<<"請輸入數字:" ;
  7.     cin>>a ;
  8.     cout<<"現在a是:"<<a<<endl;
  9. system ("pause");
  10. return 0;
  11. }
複製代碼
Attention Seeker </3

TOP

  1. #include<iostream>
  2. #include<cstdlib>

  3. using namespace std;

  4. int main()
  5. {   
  6.     int a;
  7.    
  8.     cout<<"請輸入數字: ";
  9.     cin>>a;
  10.     cout<<"你輸入的數字是: "<<a<<endl;
  11.    
  12.     system("pause");
  13.     return 0;
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int Z;
  7.     cout<<"輸入代碼: ";
  8.     cin>>Z;
  9.     cout<<"剛輸入的密碼: "<<Z<<endl;
  10.     system("pause");
  11.     return 0;
  12. }
複製代碼

TOP

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

TOP

  1. #include<iostream>    //引入  <標準函示庫>     標頭檔  c standard  library
  2. #include<cstdlib>     //引入  <基本輸入輸出>   標頭檔    input  &  output  stream
  3. using namespace std;  //指定命名空間為    std
  4. int main()   //主函式
  5. {
  6.        
  7.         int a;   
  8.         cout<<"請輸入一整數: ";
  9.         cin>>a;
  10.         cout<<"你剛輸入的數字: "<<a<<endl;

  11.     system("pause");       // 讓畫面暫停
  12.     return 0;             //回傳到主控台,告知該程式已成功執行
  13. }
複製代碼

TOP

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

TOP

  1. #include<iostream>     //引入 <基本輸入輸出> 標頭檔 input & output stream
  2. #include<cstdlib>      //引入 <標準函式庫> 標頭檔 c standard library
  3. using namespace std;   //指定命名空間為 std
  4. int main()    //主函式  //你要做的事
  5. {      
  6.     int a=50;
  7.   
  8.     cout<<"a原本是:"<<a<<endl;      
  9.     cout<<"請輸入數字:";
  10.     cin>>a;
  11.    
  12.     //cout輸出  endl換行
  13.     system("pause");       //讓畫面暫停
  14.     return 0;              //回傳0到主控台,告知該程式已成功執行
  15. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int a=0;
  7.     cout<<"輸入前的a="<<a<<endl;
  8.     cout<<"輸入a:";
  9.     cin>>a;
  10.     cout<<"輸入後的a="<<a<<endl;
  11.     system("pause");
  12.     return 0;   
  13. }
複製代碼

TOP

[code]#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
    int a;
    cout<<"請輸入一整數: ";
    cin>>a;
    cout<<"你剛輸入的數字是: "<<a<<endl;
    system("pause");
    return 0;   
}

TOP

  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

返回列表