How can multiple characters be continuously output in C++ using cout?
In C++, multiple characters can be output to the standard output stream (usually the console) using consecutive << operators. Here are some examples:
- Output multiple character constants:
std::cout << 'A' << 'B' << 'C';
This will result in ABC.
- Output multiple string constants:
std::cout << "Hello" << " " << "world!";
This will print Hello world!
- Output multiple string variables:
std::string str1 = "Hello";
std::string str2 = "world!";
std::cout << str1 << " " << str2;
This will produce the output “Hello world!”
- Output multiple character variables.
char ch1 = 'A';
char ch2 = 'B';
char ch3 = 'C';
std::cout << ch1 << ch2 << ch3;
This will produce ABC.
The << operator can be used to output continuously to the standard output stream for character constants, string constants, character variables, and string variables, as long as the type supports output operator overloading.