The following methods are used to output the string type in C: use std::cout object: std::cout << string_variable uses the output operator (<<): string_variable << std: :cout
Output string type in C
In C, you can use the following method to output string type :
std::cout Object:
std::cout << string_variable
Output operator (<<):
string_variable << std:: cout
##Example:
#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>Hello, C++! Hello, C++!</code>
Note:
object output. The
manipulator can be used for line breaks.
The above is the detailed content of How to output string type in c++. For more information, please follow other related articles on the PHP Chinese website!