How to print a string using cout in C++?
In C language, cout is the output stream object in C++ language and cannot be directly used in C language. Instead, in C language, you can use the printf function to output strings. Here is an example code for outputting strings using the printf function.
#include <stdio.h>
int main() {
char str[] = "Hello, C!";
printf("%s\n", str);
return 0;
}
In the example above, %s is a formatting specifier for the printf function, used to output strings. ‘str’ is a character array that stores the string to be output. The statement printf(“%s\n”, str); will print the string stored in the ‘str’ array to the console, with a newline character added at the end.