用于从键盘获取数据:
语法:
1 #include <iostream> 2 #include <string> 3 4 using namespace std; 5 6 int main(){ 7 //整型、浮点型、字符型 8 int a = 0; 9 cout << "请给整型变量a赋值:" << endl; 10 cin >> a; 11 cout << "整型变量a=" << a << endl; 12 13 //字符串型 14 string str = "hello cpp"; 15 cout << "请给字符型变量str赋值:" << endl; 16 cin >> str; 17 cout << "字符型变量str=" << str << endl; 18 19 //布尔型 20 bool flag = false; 21 cout << "请给布尔型变量flag赋值:" << endl; 22 cin >> flag; //只要输入的值不为0,都输出1(即非假即为1) 23 cout << "布尔型变量flag=" << flag << endl; 24 25 system("pause"); 26 return 0; 27 }
标签:cout,int,C++,获取数据,include,输入 From: https://www.cnblogs.com/MorningMaple/p/16832005.html