跳转至

输入输出

cin, cout

C++的输入输出

int a, b;
cin >> a >> b;

cout << a << ' ' << b << '\n';

This operator (>>) applied to an input stream is known as extraction operator. (Extracts and parses characters sequentially from the stream)

This operator (<<) applied to an output stream is known as insertion operator. (inserts them into the output stream)

scanf, printf

C语言的输入输出

格式化输入输出语句

int a, b;
scanf("%d%d", &a, &b);
printf("%d\n", a + b);

// 占位符对应关系
int %d
double %lf
char %c
long long %lld
// 读入时间格式 12:09
int h, m;
scanf("%d:%d", &h, &m);

如果要一次输出多个变量

在双引号里面,就是要输出的格式,占位符与后面的变量一一对应

printf("%d+%d=%d", a, b, a + b);

保留小数点问题