admin 管理员组

文章数量: 1086019


2024年3月10日发(作者:c语言组个最小数)

c++ print用法

在C++中,有多种方法可以输出内容到终端。以下是几种常见的打印输出方法:

1. 使用cout和<<运算符:

```cpp

#include

int main() {

std::cout << "Hello, World!" << std::endl;

return 0;

}

```

在这个例子中,使用了iostream库中的cout对象来输出字符串"Hello, World!"。

通过<<运算符可以连续输出多个内容。

2. 使用printf函数:

```cpp

#include

int main() {

printf("Hello, World!n");

return 0;

}

```

与C语言中的用法类似,也可以使用printf函数来打印输出。需要包含头文件

cstdio。

3. 使用puts函数:

```cpp

#include

int main() {

const char* str = "Hello, World!";

puts(str);

return 0;

}

```

puts函数可以直接输出字符串。

这些只是C++中几种常见的打印输出方法,还有其他方法可根据具体需求选择。


本文标签: 输出 方法 打印输出 函数 使用