#include <iostream>
int main() {
// 输出简单字符串
std::cout << "Hello, World!" << std::endl;
// 输出整数
int num = 42;
std::cout << "The number is: " << num << std::endl;
// 输出浮点数
double pi = 3.14159;
std::cout << "The value of pi is: " << pi << std::endl;
// 输出字符
char ch = 'A';
std::cout << "The character is: " << ch << std::endl;
// 输出多个值
std::cout << "The values are: " << num << ", " << pi << ", " << ch << std::endl;
return 0;
}
#include <iostream>:包含输入输出流库,使得我们可以使用 std::cout。std::cout:用于向控制台输出内容的对象。<<:流插入运算符,用于将数据插入到输出流中。std::endl:表示换行并刷新输出缓冲区。通过这些代码示例,你可以看到如何使用 std::cout 输出不同类型的数据(字符串、整数、浮点数和字符)以及如何在同一行中输出多个值。
上一篇:c++ 容器
下一篇:c++ long
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站