doc/notebook/docs/C++/1.iostream.md

29 lines
747 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

1. `cout`: 用于标准输出,可以使用`<<`操作符将数据输出到屏幕上。
```cpp
std::cout << "Hello, world!" << std::endl;
```
2. `cin`: 用于标准输入可以使用`>>`操作符从用户输入中读取数据。
```cpp
int num;
std::cin >> num;
```
3. `endl`: 输出换行符并刷新输出缓冲区。
```cpp
std::cout << "Hello" << std::endl;
```
4. `cerr`: 用于输出错误信息通常用于标准错误流
```cpp
std::cerr << "Error: something went wrong!" << std::endl;
```
5. `fixed``setprecision`: 用于控制浮点数的输出精度
```cpp
double num = 3.14159;
std::cout << std::fixed << std::setprecision(2) << num << std::endl;
```