基本輸入輸出
這一節介紹C++的基本輸入輸出語句,很簡單,只要用到"cout<<"和"cin>>"就可以了,其實cout和cin都是標準輸入輸出流對象,他們的頭文件是<iostream>,所以要想實現輸入輸出我們都會#include<iostream> ,下面舉個簡單的例子
提醒用戶輸入自己各科成績,然后算出平均值輸出
#include<iostream>
using namespace std;
const float pi = 3.14;
int main(){
float chinese_score;
float math_score;
float engilsh_score;
cout << "please input your chinese score:";
cin >> chinese_score;
cout << "please input your math score:";
cin >> math_score;
cout << "please input your english score:";
cin >> engilsh_score;
cout << "Your average score is " << (chinese_score + math_score + engilsh_score) / 3 << endl;
return 0;
}
Paste_Image.png
是不是很簡單呢?