c++ 实例 - 创建不同类型的变量
以下实例展示了不同类型变量的创建方法:
实例
#include <iostream>
#include <string>using namespace std;
int main () { // 创建变量 int mynum = 5; // 整型 float myfloatnum = 5.99; // 单精度浮点型 double mydoublenum = 9.98; // 双精度浮点型 char myletter = 'd'; // 字符型 bool myboolean = true; // 布尔型 string mystring = "51frw"; // 字符串
// 输出变量 cout << "int: " << mynum << "n";
cout << "float: " << myfloatnum << "n";
cout << "double: " << mydoublenum << "n";
cout << "char: " << myletter << "n";
cout << "bool: " << myboolean << "n";
cout << "string: " << mystring << "n";
return 0;}
以上程序执行输出结果为:
int: 5 float: 5.99 double: 9.98 char: d bool: 1 string: 51frw
【说明】:本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!