|
| |||||||||
| Tags: c program, cpluplus, cpp, plain text, print |
![]() |
| | Thread Tools | Search this Thread |
|
#1
| |||
| |||
| How to print plain text using C++ program
I would like to know how to print with the help of C++. I searched a lot on Google and in fact found some explaining how to do this but all that was too hard to understand. I need some simple steps to do so. My requirement is just to print plain text. Is there anyone who can help me in this matter? |
|
#2
| |||
| |||
| Re: How to print plain text using C++ program
Here is a small sample code of doing it: Code: #include < iostream.h >
#include < fstream.h >
int main(void)
{
int x=1534;
char c[15];
float fval=123.556;
ofstream printer;
printer.open("lpt1");
cout<<"Enter a word (Max 14 chars): ";
cin.getline(c,14, '\n');
printer << "The values are: " << x <<" " << fval <<" "<
return 0;
} |
|
#3
| ||||
| ||||
| Re: How to print plain text using C++ program
Are you aware of file handling? If yes then this is an easy job for you. All you need to do is instead of opening the stream to a file on disk, you open it to the printer port. Here is a simple example for you to better understand the concept: Code: #include
int main()
{
int p;
cout << "Initialising..." << endl;
ofstream writeOnPrinter;
writeOnPrinter.open("lpt1:", ios::out);
cout << "Your text will be printed on printer now." << endl;
writeOnPrinter << "Hello World" << endl;
for(p = 0; p < 6; p++)
{
writeOnPrinter << p << endl;
}
writeOnPrinter << "f";
writeOnPrinter.close();
return 0;
}
__________________ Grand Theft Auto 4 PC Video Game |
|
#4
| |||
| |||
| Re: How to print plain text using C++ program
Thank you all but I think you didn't got my question. I am a beginner. I don't want to print any of my text on my printer. Instead I want it on my monitor. I know that we use to use printf in C but I think there is some different method in C++. I used the "#include<iostream>" at the beginning of my code but then also my code doesn't work. Could you explain me why? |
|
#5
| ||||
| ||||
| Re: How to print plain text using C++ program
Basically the header file is "iostream.h" and not "iostream". This is the reason why you are not getting the correct output. If, however, you are using "iostream" then you need to use "std" namespace where ever you are using "cin" or "cout" or "endl". Other than that there is no other method to get output on your output device. "cout" is more than enough for you since you are beginner. You will learn more later on during your course.
__________________ Grand Theft Auto 4 PC Video Game |
|
#6
| |||
| |||
| I dont understand what youre askin. If you want it on paper: Do the program and save it and exit out of the compiler. Go to the folder in which you saved the thing (most probably its in the same BIN folder as the compiler). Search for the file you saved and Voila ther it is AS A NOTEPAD FILE. Now you get what you asked for. Or if you really asked something like how to display something as an output just use cout<<"whatever you want here..."; Keep it simple silly. Last edited by vijayvijay7 : 19-08-2011 at 10:46 PM. |
![]() |
|
| Thread Tools | Search this Thread |
| |
Similar Threads for: "How to print plain text using C++ program" | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to paste plain-text from table | Indrayan | Windows Software | 4 | 20-07-2011 08:24 PM |
| How do you create a plain text heading in the task column? | djacob7 | Microsoft Project | 2 | 29-09-2010 08:19 PM |
| Emails being converted to plain text since AVG 8.0 | Muhammad Waqar | Networking & Security | 3 | 05-09-2009 11:49 AM |
| How to Send a Message in Plain Text in Outlook | Chain-SmokeR | Windows Software | 3 | 03-07-2009 12:18 AM |
| Differences between rich text and plain text format | Kamran | Windows Software | 4 | 19-06-2009 10:00 PM |