|
From: CARLSON, J. M. <CA...@st...> - 2003-06-10 04:37:43
|
Reply to printing - take 2 - This is a good way to print from a console. A
file could be created a console program and then printed with a system()
call. Below is a sample program that demonstrates how it works. It is
longer than it has to be to show several variations at the same time.
#include <iostream>
#include <stdlib.h>
using namespace std;
int main(void) {
// assuming c:\test.txt exits, this will work.
// c:\test.txt should be a small file because it will print 4 times.
// Notice the double backslash in the first non comment line
// The backslash is a control characher so the first one
// is stripped out before the command is executed.
system("print c:\\test.txt");
system("PRINT c:\\test.txt");
system("print C:\\TEST.TXT");
// Other ways to do the same thing.
// This line could be dangerous - unterminated string
const char* command01 = "Print C:\\test.txt"; /* do I need \0 ?
*/
const char* command02 = "Print C:\\test.txt\0"; /* \0 ends the string
*/
// This line could be dangerous - unterminated string
const char command03[] = "Print C:\\test.txt"; /* do I need \0 ?
*/
const char command04[] = "Print C:\\test.txt\0"; /* \0 ends the string
*/
system(command01);
system(command02);
system(command03);
system(command04);
// all valid dos commands can by used by system()
// you can get a list of commands by typing
// HELP + [enter key] (if installed)
//
system("PAUSE");
// notice case is not important to the system() call
return 0;
}
Jay
|