ifstream

M

Michael Sgier

Hi
i want to read a text file. but it says "incomplete type" and read
errors. Why? and finally compare to another file.
Many thanks
Michael


//path und filename
strcat(InFile1, "aha.dat");
std::ifstream InPutfile1;
char Byte;

InPutfile1.open(InFile1, std::ios::in | std::ios::binary);
// is that the same for another text file?

while(!InPutfile1.eof())
{
char NewByte;

if (!InPutfile1.fail())
{
Byte = InPutfile1.get();

//etc.

if ( InPutfile != outFile1)
 
J

Juha Nieminen

Michael said:
strcat(InFile1, "aha.dat");

Don't do that. You are asking for trouble. Instead, do this:

std::string inFile1 = "aha.dat";

(or inFile1 += "aha.dat"; if you are really appending to an existing
string.)

You can then open the file with
std::ifstream inputFile1(inFile1.c_str());
std::ifstream InPutfile1;
char Byte;

InPutfile1.open(InFile1, std::ios::in | std::ios::binary);
// is that the same for another text file?

while(!InPutfile1.eof())
{
char NewByte;

if (!InPutfile1.fail())
{
Byte = InPutfile1.get();

//etc.

if ( InPutfile != outFile1)

Without a complete compilable program it's hard to say what is it that
you are trying to achieve and what you are doing wrong.
 
M

Michael Sgier

Hi Juha
declared as:

char InFile1[100];

I don't have the c_str option and also the += is not working.

Thanks
Michael
 
A

Alan Woodland

Michael said:
Hi Juha
declared as:

char InFile1[100];

I don't have the c_str option and also the += is not working.

One possible explanation for your original question (which this post
would seem to confirm) is that you're missing appropriate #includes?

e.g.

#include <fstream>
#include <string>

would be needed to use fstream and string and might make += "not work"
and "incomplete type" errors.

Tip for the future: Include a complete, minimal example that others can
test for quicker, better replies. The natural assumption from what
you've posted so far is that you've got the right includes, although
it's looking less like that's the case now...

Alan
 
R

red floyd

Michael said:
Hi
i want to read a text file. but it says "incomplete type" and read
errors. Why? and finally compare to another file.
Many thanks
Michael


//path und filename
strcat(InFile1, "aha.dat");
std::ifstream InPutfile1;
char Byte;

InPutfile1.open(InFile1, std::ios::in | std::ios::binary);
// is that the same for another text file?

while(!InPutfile1.eof())
{
char NewByte;

if (!InPutfile1.fail())
{
Byte = InPutfile1.get();

//etc.

if ( InPutfile != outFile1)

In addition to everyone else's comments, your read loop does not
do what you think it does.

Please see FAQ 15.5

http://www.parashift.com/c++-faq-lite/input-output.html#faq-15.5
 
T

Thomas Matthews

Michael said:
Hi
i want to read a text file. but it says "incomplete type" and read
errors. Why? and finally compare to another file.
Many thanks
Michael


//path und filename
strcat(InFile1, "aha.dat");
std::ifstream InPutfile1;
char Byte;

InPutfile1.open(InFile1, std::ios::in | std::ios::binary);
// is that the same for another text file?

while(!InPutfile1.eof())
{
char NewByte;

if (!InPutfile1.fail())
{
Byte = InPutfile1.get();

//etc.

if ( InPutfile != outFile1)

The best algorithm that I have found for comparing file
content is to use buffers and compare the two buffers.

Most files are on some kind of slow access device such as
hard drives, flash memory, tape drives, etc. These devices
are "slow" to start up and love to keep going. This is
known as block reading.

Another trick is to use std::rdbuf. Create a huge buffer
and use the streams.

--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.comeaucomputing.com/learn/faq/
Other sites:
http://www.josuttis.com -- C++ STL Library book
http://www.sgi.com/tech/stl -- Standard Template Library
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,066
Latest member
VytoKetoReviews

Latest Threads

Top