码迷,mamicode.com
首页 > 编程语言 > 详细

c++基础篇---HelloWorld

时间:2018-10-10 12:07:48      阅读:158      评论:0      收藏:0      [点我收藏+]

标签:scanf   hello   cond   c中   stream   输入   面向对象   namespace   printf   

c++入门程序

c中的输入和输出,一般使用标准库中printf,scanf去进行读写。

#if 0

#include<stdio.h>
int main()
{
    //输出
    printf("hello world...\n");
    //输入
    int a = 0;
    printf("请输入一个整数:");
    scanf("%d", &a);
    return 0;
}

#endif

#if condition...#endif c/c++中的预编译指令,只有当条件满足时才去编译。

作为对比:

c++中简化了对输入输出的书写,通过引入标准命名空间std的方式使用cin,cout进行标准的输入输出。

#include<iostream>
using namespace std;
//std{
//    cout...
//iostream有一个标准的命名空间std,定义了cin,cout等关键字
//}
int main(void)
{
    //输出
    cout << "helloworld" << endl;
    //输入
    int a = 0;
    cout << "请输入一个整数:";
    cin >> a;
    cout << "a="<< a << endl;
    return 0;
}

通过书写可以看出c++完全继承c的特性,但又多了面向对象的特征。

c++基础篇---HelloWorld

标签:scanf   hello   cond   c中   stream   输入   面向对象   namespace   printf   

原文地址:https://www.cnblogs.com/knight11/p/9762658.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!