C++: Output An Entire Text File- Can It Be Done?

hello!!!

Is it possible to read in to a program an entire ".txt" file, instead of reading information individually into variables!!

Basically... i'm writing a magazine inventory program. When the user inputs some information, it is written to a text file.... then when they input another magazine, this is saved to the same txt file...etc....

I then have to give the user the option to see all entries, within the program.

Is it possible to read in to a program an entire ".txt" file, instead of reading information individually into variables!!

You would read the contents of the file into say, a string variable.

Can I output an entire txt file to screen?

Once you have the contents on the file stored in a variable, you can print it to screen.

Incidentally, have you considered using SQLite for an embedded relational database engine instead of writing your own flatfile database?

Originally Posted by Bjarne Stroustrup (2000-10-14)

I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.

Of course you can. This is not the stone age, after all.
Open file. Seek to end of file, get position to get size (or just use an API).
Allocate a big enough buffer, then use istream.read to read the entire file into buffer and output to screen.

Originally Posted by Adak

io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.

Originally Posted by Salem

You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

in_file_mags.open("H:\\mag_store.txt");
THAT is how you open a file.
And I really don't deal with C++ I/O, so I don't know how the search functions works.
I believe seekg seeks the read position in the file.

Originally Posted by Adak

io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.

Originally Posted by Salem

You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.