【C++】输入&输出

一.打印一个Hello world

#include<iostream>

using namespace std;

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

使用 cout(标准输出)cin(标准输入) 时,必须包含 < iostream> 头文件和 std标准命名空间

二.C++输入输出不需要增加数据格式控制,例如%d,%c等

#include<iostream>

using namespace std;

int main()
{
	int a;
	double b;
	char c;

	cin >> a;
	cin >> b >> c;

	cout << a << endl;
	cout << b << c << endl;
	return 0;
}
#include<iostream>
using std::cout;
using std::cin;

int main()
{
	int a;
	double b;
	char c;

	cin >> a;
	cin >> b >> c;

	cout << a ;
	cout << b << c ;
	return 0;
}
#include<stdio.h>
#include<iostream>
#pragma warning(disable:4996)
using std::cout;
using std::cin;
void test()
{
	int a = 10;
	printf("%d\n", a);
	printf("output\n");
	std::cout << a;
	cout << a;
	
	int b;
	scanf("%d", &a);

	cin >> a >> b;
	cout << a << " " << b << "\n";

}
int main()
{
	test();
	return 0;
}

三.总结

①C++头文件没有 .h后缀
②C++头文件定义的所有成员
③C++输入输出:
头文件:< iostream>
命名空间:std
输入cin:支持连续输入 ----> cin >>变量 >>变量>>…
输出cout:支持连续输出 ---->cout <<变量 <<变量<<…

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值