C++輸入輸出:
string name;
int age;
cout << "輸入名字:";
cin >> name>>age;
cout << name << age<<endl;
占位符:
%d, %i 代表整數(shù)
%f 浮點
%s 字符串
%c char
%p 指針
%fL 長log
%e 科學(xué)計數(shù)
%g 小數(shù)或科學(xué)計數(shù)。
%a,%A 讀入一個浮點值(僅C99有效)。
%c 讀入一個字符稍途。
%d 讀入十進(jìn)制整數(shù)疚沐。
%i 讀入十進(jìn)制违柏,八進(jìn)制侣滩,十六進(jìn)制整數(shù)摊册。
%o 讀入八進(jìn)制整數(shù)罢缸。
%x,%X 讀入十六進(jìn)制整數(shù)篙贸。
%s 讀入一個字符串,遇空格祖能、制表符或換行符結(jié)束歉秫。
%f,%F,%e,%E,%g,%G 用來輸入實數(shù),可以用小數(shù)形式或指數(shù)形式輸入养铸。
%p 讀入一個指針雁芙。
%u 讀入一個無符號十進(jìn)制整數(shù)。
%n 至此已讀入值的等價字符數(shù)钞螟。
%[] 掃描字符集合兔甘。
%% 讀 % 符號
定義函數(shù)步驟:
include<iostream>
//函數(shù)聲明(只需寫上參數(shù)的數(shù)據(jù)類型)
void test1();
void test2(int, int);
int test3();
int test4(int, int);
int main() {
//函數(shù)調(diào)用
test1();
test2(1, 2);
int s=test3();
cout << s << endl;
int ss = test4(2, 3);
cout << ss << endl;
}
//函數(shù)定義
void test1() {
cout << "無參無返" << endl;
}
void test2(int a, int b) {
cout << a + b << endl;
}
int test3() {
return 10;
}
int test4(int a, int b) {
return a * b;
}