Jump to content
  • Advertisement
Sign in to follow this  
Simian Man

Printing a text file (C++)

This topic is 4870 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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!

Share this post


Link to post
Share on other sites
Advertisement
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...)

Share this post


Link to post
Share on other sites
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.
}



Share this post


Link to post
Share on other sites
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..

Share this post


Link to post
Share on other sites
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 :-).

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!