第一个C++程序

二、第一个C++程序
01first.cpp

#include <iostream>

int main(void){
	std::cout << "hello world!" << std::endl;
	return 0;
}

1、在终端的两种编译程序方法:
第一种:
gcc 01first.cpp -lstdc++
./a.out

第二种:
g++ 01first.cpp//推荐

2、文件扩展名
1).cpp
2).cxx
3).cc
4).c

3、头文件
//包含了标准C++中所有和I/O相关的类型、对象和函数
#include

注:在C++中标准C的头文件依然可以使用
#include <stdio.h>#include
#include <stdlib.h>
#include
#include <string.h>==#include
……

#include <iostream>
//#include <stdio.h> C语言的风格,(1)
#include <cstdio> //C++的风格,等同于(1)
int main(void){
	std::cout << "hello world! "<< std::endl;
	printf("Hello world!\n");
	return 0;
}

4、标准的输入和输出
1)cin对象表示标准输入//类似scanf
eg:

int num;
scanf("%d", &num);//C中
cin >> num;//C++中
//其中">>"称为提取操作符

int i;
double d;
scanf("%d%lf", &i, &d);//C
cin >> i	>>d;//C++

2)cout对象表示标准输出//类似printf
eg:

int num = 23;
printf("num = %d\n", num0);//C
cout << "num = " << num;//C++
//其中"<<"称为插入操作符
//注:endl == "\n"

int i = 100;
double d = 3.14;
printf("%d,%lf\n", i, d);
cout << i << ',' << d << endl;

5、"std::"标准名字空间
C++标准库中的所有函数、变量、类型都是在std空间中

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值