何时包含引号

When to include quotation marks for cout

本文关键字:何时包      更新时间:2023-10-16

下面的示例中,cout 语句中的引号有什么作用?

cout << somevariable << " ";

我什么时候需要包括它们?

" "表示空间。例如,当您要打印 2 个用空格分隔的字符串变量时:

std::string str1 = "Hello";
std::string str2 = "World";
std::cout << str1 <<" "<< str2;

输出:

Hello World

如果您在cout中询问",则用于在双引号内打印任何文本。
std::cout << "Any Text";

记住里面的空间" "也是一个文本。