1. 程式人生 > 其它 >資料型別-資料的輸入

資料型別-資料的輸入

點選檢視程式碼
#include<iostream>
#include<string> 

using namespace std;


int main()
{
	//整型
	int a = 0;
	cout << "給整型變數a賦值:" << endl;
	cin >> a;
	cout << "a = " << a << endl;

	//浮點型
	float b = 1.0f;
	cout << "給浮點型變數b賦值:" << endl;
	cin >> b;
	cout << "b = " << b << endl;

	//字元型
	char ch = 'a';
	cout << "給字元型變數ch賦值:" << endl;
	cin >> ch;
	cout << "ch = " << ch << endl;

	//字串
	string str = "asd";
	cout << "給字串變數str賦值:" << endl;
	cin >> str;
	cout << "str = " << str << endl;

	//布林型
	bool flag = false;
	cout << "給布林型別flag賦值:" << flag << endl;
	cin >> flag;	//bool型別 只要是非0的值都代表真
	cout << "flag = " << flag << endl;

	system("pause");

	return 0;
}