Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cout (standard output) in C++

Tags:

c++

// 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 ....")

like image 422
w4j3d Avatar asked Nov 28 '10 17:11

w4j3d


People also ask

Is cout standard output?

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).

Is there a cout in C?

cin and cout are streams and do not exist in C. You can use printf() and scanf() in C.

What is cout << 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.

Is cout represents the standard output stream in C++?

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.


1 Answers

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"
like image 184
Etienne de Martel Avatar answered Sep 30 '22 12:09

Etienne de Martel