What does mean scrn?

Nov 16, 2011 at 1:56pm
what is the propose of bold lines in this program? What does mean scrn?

#include <iostream.h>
#include <fstream.h>
#include <stdlib.h>
/* Declare the stream objects */
ifstream inFile;
ofstream scrn, prnt;
main()
{
char inChar;
inFile.open("C:\\Documents and Settings\\ABC\\Desktop\\mywork\\seekg.txt", ios::in); // Open the file for input
if(!inFile)
{
cout << "Error opening file"<< endl;
}
scrn.open("CON", ios::out);
while(inFile.get(inChar))
{
scrn << inChar;
}
scrn.close();
inFile.seekg(0l, ios::beg);
prnt.open("LPT1", ios::out);
while(inFile.get(inChar))
{
prnt << inChar;
}
prnt.close();
inFile.close();
}
Nov 16, 2011 at 2:55pm
This line of code here:
ofstream scrn, prnt;
create two objects of type ofsteram. One of these objects is called scrn, and the other one is called prnt. Thus, scrn is an object of type ofstream.
Time to learn what a variable is: http://cplusplus.com/doc/tutorial/variables/


scrn.open("CON", ios::out);
This line says "take that object I made called scrn, and use one of its function. Use the function it has which is called open. This function it has, called open, takes two parameters. Make the first parameter "CON" and the second parameter ios::out."

Time to learn what functions are: http://cplusplus.com/doc/tutorial/functions/
and how classes have functions: http://cplusplus.com/doc/tutorial/classes/
Last edited on Nov 16, 2011 at 2:55pm
Nov 16, 2011 at 5:29pm
both the object open the file for writting in to the file .
But ,,,, I am not able to understand what exactly are you trying to do ?
Last edited on Nov 16, 2011 at 5:30pm
Nov 16, 2011 at 6:37pm
1.ofstream is used to write to files.
2.ifstream is used to read from files.
3.fstream is used to both read from and write to files.

scrn and prnt are objects of type ofstream.
It means scrn and prnt can be used as pointers to files.

scrn.open ("CON", ios::out)
scrn is used to open the file named "CON" in output mode (ios::out) and
prnt.open ("LPT1", ios::out)
prnt is used to open the file named "LPT1" in output mode.

I assume that the object named scrn is used to save data to be written to the console
and object prnt is used to save data to be printed.

Nov 16, 2011 at 8:41pm
The code is using ofstream to write to the console (CON) -- or screen -- and to a printer (LPT1 = Line Printer Terminal 1). Assuming there is a printer attached to the parallel port.

That is, CON and LPT1 represent the actual devices. Not files on disk for writing to the devices later.

"Can ofstream be used for printing on a printer"
http://stackoverflow.com/questions/6545701/can-ofstream-be-used-for-printing-on-a-printer
Last edited on Nov 16, 2011 at 8:51pm
Topic archived. No new replies allowed.