![]() |
|
|
#1 | ||
|
College Starter
Join Date: Oct 2000
Location: Calgary
|
C++: I/O File Stream Objects
Every example I've seen involving file stream objects either hardcodes the filename or when writing to file, hardcodes the input or lets the user type in a few lines.
What I'm trying to do is open a pre-existing text file (done), have the user type in a file name (done), and save the data from the opened text file into the user-defined output file (not done). I can display the contents on-screen. The biggest problem is finding a way to link the data to the user-defined filename in a function that can handle the task. Code:
I know I'm misunderstanding something because it shouldn't be as difficult as I'm making it. Any help is always appreciated. |
||
|
|
|
|
|
#2 |
|
General Manager
Join Date: Oct 2000
Location: The Satellite of Love
|
Well, you could get the info from the first file using the member function getline. And then put that into the new file. I'll try to write up a small program showing how to do it. (In the meantime, someone else might answer better.
) |
|
|
|
|
|
#3 |
|
General Manager
Join Date: Oct 2000
Location: The Satellite of Love
|
Code:
Last edited by sabotai : 04-21-2004 at 08:08 PM. |
|
|
|
|
|
#4 |
|
General Manager
Join Date: Oct 2000
Location: The Satellite of Love
|
ugh...the formatting in the code blocks suck, but I think you can read it.
![]() |
|
|
|
|
|
#5 |
|
Pro Starter
Join Date: Jul 2003
Location: South Bend, IN
|
Hmm... there ought to be a cute way to do it using stream iterators. If I remember right, though, you're in a class, and stream iterators are probably beyond the scope at this point (although they probably ought to be included in any serious course work on the streams).
Anyway, sabotai's method looks good to me, and I think the streams will take care of buffering to make sure that the performance is competitive. |
|
|
|
|
|
#6 |
|
College Starter
Join Date: Oct 2000
Location: Calgary
|
That's great. Thank-you.
I'm writing my final today. One trace (most likely involving 2-D arrays), one program we'll have to code, 6 short answer and a small section dealing with classes - a topic we just touched on in the last week (wouldn't you know). I think for the summer I'm going to pick up a better text and hack away on my own. Thanks again for the help. Last edited by Karim : 04-22-2004 at 08:25 AM. |
|
|
|
|
|
#7 |
|
Pro Starter
Join Date: Jul 2003
Location: South Bend, IN
|
If you're looking for good general C++ texts, a couple are:
Accelerated C++ by Koenig and Moo, has a great reputation as a pure C++ text (rather than text that starts with C and moves on to C++ features) The C++ Standard Library - A Tutorial and Reference by Josuttis, a great way to learn how much you can do with the standard library I have More Exceptional C++ by Sutter and More Effective C++ by Meyers on my bookshelf, but I haven't gotten to them. I'd also like to pick up the originals if I get a chance. Last edited by Mr. Wednesday : 04-23-2004 at 12:14 AM. |
|
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
|
|