Results 1 to 6 of 6

Thread: How to print plain text using C++ program

  1. #1
    Join Date
    Jan 2010
    Posts
    46

    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. #2
    Join Date
    May 2008
    Posts
    2,012

    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. #3
    Join Date
    Oct 2005
    Posts
    2,393

    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;
     }

  4. #4
    Join Date
    Jan 2010
    Posts
    46

    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. #5
    Join Date
    Oct 2005
    Posts
    2,393

    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.

  6. #6
    Join Date
    Aug 2011
    Posts
    1

    idea Re: How to print plain text using C++ program


    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 09:46 PM.

Similar Threads

  1. How to paste plain-text from table
    By Indrayan in forum Windows Software
    Replies: 4
    Last Post: 20-07-2011, 07:24 PM
  2. User details sent in plain text by windows security
    By Script in forum Networking & Security
    Replies: 5
    Last Post: 28-04-2011, 11:20 AM
  3. Emails being converted to plain text since AVG 8.0
    By Muhammad Waqar in forum Networking & Security
    Replies: 3
    Last Post: 05-09-2009, 10:49 AM
  4. How to Send a Message in Plain Text in Outlook
    By Chain-SmokeR in forum Windows Software
    Replies: 3
    Last Post: 02-07-2009, 11:18 PM
  5. Differences between rich text and plain text format
    By Kamran in forum Windows Software
    Replies: 4
    Last Post: 19-06-2009, 09:00 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,711,708,913.48754 seconds with 16 queries