Skip to main content
GameDev.net gamedev.net
🔒 Locked

Printing a text file (C++)

Started by Simian Man Jun 16, 2005 at 2:26 PM 4 replies 16.1k views
Original Post
Simian Man
Simian Man
Is there any way to do this on Windows? I am writing a cryptogram generator, and would like the user to be able to print the cryptogram out automatically. Thanks for any help!
DesignerX
DesignerX
You load the file as you usually will do and you can use the TextOut() function to print text on windows. If you want check the SDK for choosing a proper font for your task. (look for CreateFont() and the like...)
There is nothing that can't be solved. Just people that can't solve it. :)
MaulingMonkey
MaulingMonkey
Well here's one way (in C++ - the language really is more important than the OS ;-) ):

#include <iostream>#include <fstream>#include <iterator>#include <algorithm>using namespace std;int main ( void ) {    ifstream file( "filename.txt" );    istream_iterator< char > begin( file ) , end;    ostream_iterator< char > output( cout );    copy( begin , end , output );}


That will print the whole file though. Assuming you wanted something less extreme, here's another example:

#include <iostream>#include <fstream>#include <string>#include <vector>using namespace std;int main ( void ) {    ifstream file( "filename.txt" ); //opens a file...    vector< string > lines; //we'll store lines in here...    while ( file ) { //while the file is good...        string line;        getline( file , line ); //get a line from file and put it into line        if ( ! line.empty() ) lines.push_back( line ); //if the line isn't empty, add it to lines.    }    cout << lines[ rand() % lines.size() ] << endl; //print a random line.}
DvDmanDT
DvDmanDT
Hmm.. Are you sure the OP didn't mean print as in use printer?

Even if he didn't can anyone please post a link or a keyword to search for, to find info on printing? In windows that is..
MaulingMonkey
MaulingMonkey
Quote:
Original post by DvDmanDT
Hmm.. Are you sure the OP didn't mean print as in use printer?

Nope :-P.
Quote:
Even if he didn't can anyone please post a link or a keyword to search for, to find info on printing? In windows that is..

Goto http://msdn.microsoft.com/, which is the home page of the MSDN, the MicroSoft Developer Network, which has a whole bunch of information about Microsoft's Compilers, APIs, etc. I'd just enter the term "printer" (prehaps along with "C++" or whatever language you're using) into the search box and go :-).
DesignerX
DesignerX
Quote:
Original post by DvDmanDT
Hmm.. Are you sure the OP didn't mean print as in use printer?


Ahh, yeah :) , I think you are right.
Sorry but I never used printers so I can't help here

There is nothing that can't be solved. Just people that can't solve it. :)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.