English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

we define :
'ofstream out ("output.zz");
then
out<<0;
what does out<<0 mean?

2006-07-06 17:05:59 · 2 answers · asked by simona 1 in Computers & Internet Programming & Design

and what does out<<1 do?

2006-07-06 17:29:06 · update #1

2 answers

Hi. You must be knowing that 'out' here is a file object since you have declared it using the 'ofstream' class. A file of the name "output.zz" is attached to the file object ready to be written onto.

We use the '<<' operator with files in a manner similar to using it with 'cout'. Remember, to display a string or a variable on the screen we give this statement:

cout<<"Hello World!";

By doing this the output has been 'redirected' to be displayed on the monitor (which is regarded as the standard output console, hence 'cout'). In your question, the statement,

out<<0;

is similar to the cout statement, the only difference being that here the output is redirected to the file stream 'out', and thus the file "output.zz" which is attached to it.

So you will see that on executing the above statements, a file "output.zz" is created in the current working folder and if you open it with, say Notepad, it will contain a single digit '0'. If you do:

out<<1;

a '1' will be there instead of a '0'. You can even write a string onto a file, such as:

out<<"Hello!";

2006-07-06 18:29:46 · answer #1 · answered by Jayant Dhawan 2 · 1 0

It's usual misunderstanding of operators << and >>
For bit operations, they shift the value right or left.
For instance,
a = 0x07;
a <<= 8;
will make a be 0x70;
a = 0x07;
a >>= 1;
will make a be 3.
For streams, it has quite another sense.
Operator << is output operator and operator >> is input one.

2006-07-07 01:42:46 · answer #2 · answered by alakit013 5 · 0 0

fedest.com, questions and answers