// my first program in C++
#include <iostream>
using namespace std;
int main ()
{
cout << "Hello World!";
return 0;
}
Is cout
an object?
If so, where is it instantiated? (I don't see something like "new ....
")
Standard output (cout) On most program environments, the standard output by default is the screen, and the C++ stream object defined to access it is cout . For formatted output operations, cout is used together with the insertion operator, which is written as << (i.e., two "less than" signs).
cin and cout are streams and do not exist in C. You can use printf() and scanf() in C.
The cout command is a data stream which is attached to screen output and is used to print to the screen, it is part of the iostream library.
std::cout is an object of class ostream that represents the standard output stream oriented to narrow characters (of type char). It corresponds to the C stream stdout. The standard output stream is the default destination of characters determined by the environment.
cout is a global object declared somewhere in <iostream>.
By the way, unlike in Java or C#, you don't need new
to create an object. For instance, this will work:
std::string str; // creates a new std::string object called "str"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With