在 C++ 中输出 string 类型有以下方法:使用 std::cout 对象:std::cout << string_variable使用输出运算符(<<):string_variable << std::cout

C++ 中输出 string 类型
在 C++ 中,您可以使用以下方法来输出 string 类型:
std::cout 对象:
std::cout << string_variable输出运算符(<<):
立即学习“C++免费学习笔记(深入)”;
string_variable << std::cout示例:
<code class="cpp">#include <iostream>
#include <string>
using namespace std;
int main() {
string my_string = "Hello, C++!";
// 使用 std::cout 对象输出
cout << my_string << endl;
// 使用输出运算符输出
my_string << cout << endl;
return 0;
}</code>输出:
<code>Hello, C++! Hello, C++!</code>
注意:
std::cout 对象输出更常见。endl 操纵符可用于换行。
c++怎么学习?c++怎么入门?c++在哪学?c++怎么学才快?不用担心,这里为大家提供了c++速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号