Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 09-05-2005, 03:38 PM   #1 (permalink)
Salchester
Salchester
 
Salchester's Avatar
 
Join Date: Jul 2005
Location: In a house
Posts: 230
Salchester is an unknown quantity at this point
Printing File Data (Via a Printer)

I am currently making a program that will read information from a file, but, i would also like to allow the user to print the current record(s) from the file via a printer. How can this be done.

Many Thanks

Here's the coding i have so far:

Quote:
#include <iostream.h>
#include <fstream.h>
#include <ctype.h>
#include <conio.h>
#include <dos.h>

int main(void)
{
int id;
char name[50];
char next;

ifstream data (".\\data.txt");
do
{
clrscr();
data >> id;
data >> name;
cout << "ID: " << id << endl;
cout << "Name: " << name;
cout << "\n\nShow Next? Y/N: ";
cin >> next;
next = toupper (next);
} while (next == 'Y');
data.close();
return 0;
}
__________________
Many Thanks, in advance!

Salchester.
The Future Is Here - Are You Ready?
Salchester is offline   Reply With Quote
Old 09-05-2005, 06:10 PM   #2 (permalink)
Locutus
Registered User
 
Join Date: Aug 2005
Posts: 20
Locutus is on a distinguished road
Your includes seem to suggest you're talking about DOS-style printing, in which case I *think* you should simply be able to do something like this:
Code:
std::ofstream printer("LPT1", std::ios::binary);
Btw, although writing "int main(void)" isn't wrong as such, it is generally considered bad style. Just stick to "int main()", IMO.
Locutus is offline   Reply With Quote
Old 09-06-2005, 10:39 AM   #3 (permalink)
Salchester
Salchester
 
Salchester's Avatar
 
Join Date: Jul 2005
Location: In a house
Posts: 230
Salchester is an unknown quantity at this point
Printing File Data (Via a Printer)

How do i print using basic coding, i don't understand the coding you supplied. I am sort of just a beginner.

Would i need to put the path of the file in the code as well, if so where do i put it?

Many Thanks
__________________
Many Thanks, in advance!

Salchester.
The Future Is Here - Are You Ready?
Salchester is offline   Reply With Quote
Old 09-06-2005, 12:41 PM   #4 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,544
Valmont is on a distinguished road
Experiment with this:
Code:
std::ofstream printer("LPT1", std::ios::out);
std::string MyString("Hello everybody!");
printer << MyString;
__________________
Valmont is offline   Reply With Quote
Old 09-06-2005, 02:07 PM   #5 (permalink)
Salchester
Salchester
 
Salchester's Avatar
 
Join Date: Jul 2005
Location: In a house
Posts: 230
Salchester is an unknown quantity at this point
Can you use basic coding please, as i don't understand this! I haven't got a clue on how this works.

How come everybody uses the std:: coding?

Many Thanks
__________________
Many Thanks, in advance!

Salchester.
The Future Is Here - Are You Ready?
Salchester is offline   Reply With Quote
Old 09-06-2005, 04:44 PM   #6 (permalink)
Locutus
Registered User
 
Join Date: Aug 2005
Posts: 20
Locutus is on a distinguished road
Quote:
Originally Posted by Salchester
Can you use basic coding please, as i don't understand this! I haven't got a clue on how this works.

How come everybody uses the std:: coding?

Many Thanks
Namespaces you mean?

In short, namespaces are a way to group related stuff, like groups of functions and variables together.

Suppose you declare a namespace "my", with a function "f"
Code:
namespace my
{
        void f();
}
You can then call f() by writing
Code:
my::f();
Apart from keeping your code organised, one of the more usefull things about using namespaces is that it helps prevent name clashes.

Suppose you had two headers, my.h and your.h, each of which declare a number of functions and variables.

Code:
//my.h
int i;
void f();
bool g();

//your.h
char c;
void f();
void h();
Now, you can't include both at the same time, because the function "void f()" is declared in both headers.

If, on the other hand you put the declarations each in their own namespace, you can.
Code:
//my.h
namespace my
{
        int i;
        void f();
        bool g();
}

//your.h
namespace your
{
        char c;
        void f();
        void h();
}
And call with
Code:
my::f();
your::f();
There is actually a lot more stuff to know about namespaces, but that's pretty much the basis. Pretty much all the stuff in the standard library is inside the namespace "std", thus all the stuff like std::string, std::ofstream, etc.

For historical reasons however, there are usually two "versions" of most headers in the standard library. Eg, #include <string.h> and #include <string>, #include <iostream.h> and #include <iostream>, etc.

The difference is that the "traditional", .h versions of the headers declare everything in the global namespace, while the versions without the .h put it inside the "std" namespace.

Code:
#include        <iostream>

int main()
{
        std::cout << "Hello World!" << std::endl;

        return 0;
}
vs
Code:
#include        <iostream.h>

int main()
{
        cout << "Hello World!" << endl;

        return 0;
}
The version with namespaces is generally preferred.
Locutus is offline   Reply With Quote
Old 09-07-2005, 02:31 AM   #7 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,544
Valmont is on a distinguished road
You could also spend some time in this thread:
return types
__________________
Valmont is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
'old-skool' server code enhancement zyrxfz Standard C, C++ 11 06-14-2005 06:17 AM
Output problem with file manipulation (newbie) crazyant Java 4 03-11-2005 02:03 PM


All times are GMT -8. The time now is 01:50 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting