C++数据输入
目录
1、整型
#include<iostream>
#include<string>
using namespace std;
int main() {
int a = 0;
cout << "请给整型变量a赋值:" ;
cin >> a;
cout << "整型变量a=" << a<<endl;
system("pause");
return 0;
}
请给整型变量a赋值:1
整型变量a=1
请按任意键继续. . .
2、浮点型
#include<iostream>
#include<string>
using namespace std;
int main() {
float f = 3.14f;
cout << "请给浮点型变量f赋值:";
cin >> f;
cout << "浮点型变量f=" << f << endl;
system("pause");
return 0;
}
3、字符型、字符串型、布尔类型
#include<iostream>
#include<string>
using namespace std;
int main() {
//3、字符型
char ch = 'a';
cout << "请给字符型变量赋值:";
cin >> ch;
cout << "字符型变量ch=" << ch<<endl;
//4、字符串型
//string str = "helloworld";
//cout << "请给字符串赋值:";
//cin >> str;
//cout << "字符串变量str=" << str << endl;
//布尔类型
//bool falg = false;
//cout << "请给布尔类型flag赋值:";
//cin >> falg;//bool类型非0整型代表为真
//cout << "布尔类型falg=" << falg << endl;
system("pause");
return 0;
}