Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

difference between cout and write in c++

Tags:

c++

I am still confused about the difference between ostream& write ( const char* s , streamsize n ) in c++ and cout in c++ The first function writes the block of data pointed by s, with a size of n characters, into the output buffer. The characters are written sequentially until n have been written. whereas cout is an object of class ostream that represents the standard output stream. It corresponds to the cstdio stream stdout. Can anyone clearly bring out the differences between the two functions.

like image 1000
Poulami Avatar asked Aug 08 '11 17:08

Poulami


People also ask

What is difference between cout and printf?

cout is a object for which << operator is overloaded, which send output to standard output device. The main difference is that printf() is used to send formated string to the standard output, while cout doesn't let you do the same, if you are doing some program serious, you should be using printf().

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

What does cout write do?

It is used to display the output to the standard output device i.e. monitor. It is associated with the standard C output stream stdout. The data needed to be displayed on the screen is inserted in the standard output stream (cout) using the insertion operator(<<).


1 Answers

ostream& write ( const char* s , streamsize n );

Is an Unformatted output function and what is written is not necessarily a c-string, therefore any null-character found in the array s is copied to the destination and does not end the writing process.

cout is an object of class ostream that represents the standard output stream.
It can write characters either as formatted data using for example the insertion operator ostream::operator<< or as Unformatted data using the write member function.

like image 197
Alok Save Avatar answered Oct 20 '22 01:10

Alok Save