Which function is used to write a single character to the console in C++ ?
Please first select an option.
The correct answer is C) cout.put(ch)r
In C++, the cout object is used to perform output to the console (standard output). The cout.put() function is specifically used to write a single character to the console. Let's briefly explain each option:
- A) write(ch) : There is no standard function called write() in C++ to write a single character to the console. This is an invalid option.
- B) printf(ch) : printf() is a C function, not a C++ function. It is used to perform formatted output. To print a single character with printf(), the correct format specifier should be used, such as %c. So, the correct usage should be printf("%c", ch).
- C) cout.put(ch) : This is the correct answer. The cout.put() function is a member function of the cout object. It writes a single character to the console.
- D) cout.putline(ch) : This option is incorrect. There is no function called cout.putline() in C++. The correct function for writing a line of text to the console is cout << "text", using the stream insertion operator <<.