C++的输入和输出

C++的输入

scanf(): 从键盘(标准输入)读取数据

#include <iostream>
#include<cstdio>
using namespace std;
int main()
{
	int a;
	//读取单个字符
	scanf("%d", &a);  //从键盘读取一个数字
	printf("%d\n", a);  //打印出a的值

	int b, c;
	//读取多个字符
	scanf("%d %d", &b, &c);
	printf("%d %d\n", b, c);
	//"\n"换行

	return 0;
}

样例
在这里插入图片描述

cin : 从键盘(标准输入)读取数据

#include<iostream>
using namespace std;
int main()
{
	int a;
	//读取单个字符
	cin >> a;
	cout << a << endl;

	int b, c;
	//读取多个字符
	cin >> b >> c;
	cout << b << " " << c << endl;
	//"endl"换行
	
	return 0;
}

样例
在这里插入图片描述

C++的输出

printf() :在控制台打印数据

#include <iostream>
#include<cstdio>
using namespace std;
int main()
{
	int a;
	a = 6;
	printf("%d\n", a);

	return 0;
}

样例
在这里插入图片描述

cout : 在控制台打印数据

#include <iostream>
using namespace std;
int main()
{
	int a;
	a = 6;
	cout << a << endl;

	return 0;
}

在这里插入图片描述
在后面还会写字符型的输入

对大家有用的话就点个赞吧(。・ω・。)ノ♡

  • 3
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值