标签:
#include <iostream>
// C++自带的标准头文件都是没有.h的
// 就相当于C语言的<stdio.h>
// 提前使用命名空间std
using namespace std;
int main(int argc, const char * argv[]) {
// cout在控制台输出一些信息
// 相当于C语言的printf函数
std::cout << "Hello, World!\n";
// 命名空间
// cout 这个 对象 是定义在 std 命名空间中的
// cin 接收键盘的输入
int age;
double height;
char name[10];
cout << "请输入年龄:";
cin >> age;
cout << "请输入身高:";
cin >> height;
cout << "请输入姓名:";
cin >> name;
cout << "My age is " << age << ", height is " << height <<", name is " << name << endl;
return 0;
}
C++与C语言对比:
int age;
double height;
char name[10];
C++:
cout << "请输入年龄:";
cin >> age;
cout << "请输入身高:";
cin >> height;
cout << "请输入姓名:";
cin >> name;
cout << "My age is " << age << ", height is " << height <<
", name is " << name << endl;
C:
printf("请输入年龄:");
scanf("%d", &age);
printf("请输入身高:");
scanf("%lf", &height);
printf("请输入姓名:");
scanf("%s", name);
printf("My age is %d, height is %f, name is %s\n", age, height, name);
标签:
原文地址:http://www.cnblogs.com/YuanYe1/p/5035035.html