read in text & binary file

M

Mike

Hi
to compare/read in a binary and a text file, i declare:

std::ifstream InPutfile;

InPutfile.open(InFile, std::ios::in | std::ios::binary);

and get "incomplete type". This worked with a previous gcc
Thanks Michael
 
A

Alf P. Steinbach

* Mike:
Hi
to compare/read in a binary and a text file, i declare:

std::ifstream InPutfile;

InPutfile.open(InFile, std::ios::in | std::ios::binary);

and get "incomplete type". This worked with a previous gcc
Thanks Michael

"InFile" is not declared.

Try to post a complete, small program exhibiting the problem.


Cheers & hth.,

- Alf
 
M

Mike

#include <iostream>
#include <fstream>

const char *pFileName = "Air_X/";
char gPluginDataFile[255];
char InFile[100];

strcat(gPluginDataFile, pFileName);
strcpy(InFile, gPluginDataFile);
strcat(InFile, "CX.txt");

std::ifstream InPutfile;

InPutfile.open(InFile, std::ios::in | std::ios::binary);
 
A

Alf P. Steinbach

* Mike:
#include <iostream>
#include <fstream>

const char *pFileName = "Air_X/";
char gPluginDataFile[255];
char InFile[100];

strcat(gPluginDataFile, pFileName);
strcpy(InFile, gPluginDataFile);
strcat(InFile, "CX.txt");

std::ifstream InPutfile;

InPutfile.open(InFile, std::ios::in | std::ios::binary);

Ah, easy, you can't have non-declarative statements like 'strcat' at namespace
scope.

Every C++ program needs to have a function 'main', like

int main()
{
// Your statements go here.
}


Cheers & hth.,

- Alf
 
J

John H.

#include <iostream>
#include <fstream>

        const char *pFileName = "Air_X/";
        char gPluginDataFile[255];
        char InFile[100];

        strcat(gPluginDataFile, pFileName);
        strcpy(InFile, gPluginDataFile);
        strcat(InFile, "CX.txt");

        std::ifstream InPutfile;

        InPutfile.open(InFile, std::ios::in | std::ios::binary);

You have many statements here, but there is no function. A C++
program usually starts in the function titled main. This is very
basic C++. I suggest reading an introduction to C++ that can show you
a "Hello World" program before you get into more complicated things.
As a program, your statements might look something like this:

#include <iostream>
#include <fstream>
#include <cstring> // for strcat strcpy

int main()
{
const char *pFileName = "Air_X/";
char gPluginDataFile[255];
char InFile[100];

strcat(gPluginDataFile, pFileName);
strcpy(InFile, gPluginDataFile);
strcat(InFile, "CX.txt");

std::ifstream InPutfile;
InPutfile.open(InFile, std::ios::in | std::ios::binary);

return 0;
}
 
V

Victor Bazarov

John said:
#include <iostream>
#include <fstream>

const char *pFileName = "Air_X/";
char gPluginDataFile[255];
char InFile[100];

strcat(gPluginDataFile, pFileName);
strcpy(InFile, gPluginDataFile);
strcat(InFile, "CX.txt");

std::ifstream InPutfile;

InPutfile.open(InFile, std::ios::in | std::ios::binary);

You have many statements here, but there is no function. A C++
program usually starts in the function titled main. This is very
basic C++. I suggest reading an introduction to C++ that can show you
a "Hello World" program before you get into more complicated things.
As a program, your statements might look something like this:

#include <iostream>
#include <fstream>
#include <cstring> // for strcat strcpy

int main()
{
const char *pFileName = "Air_X/";
char gPluginDataFile[255];

An uninitialised array. Make a note of that.
char InFile[100];

strcat(gPluginDataFile, pFileName);

What's in the 'gPluginDataFile' before the 'strcat'? That array is
*uninitialised* (remember?). And 'strcat' *requires* that the
destination buffer contains a C-string. Does it? You don't know. It's
OK not to know, *if* you don't care. But in this case do *NOT* use
strcat, use strcpy. And what's the purpose of that array anyway? Why
can't you just drop it and use 'pFileName' instead on the next line?
strcpy(InFile, gPluginDataFile);
strcat(InFile, "CX.txt");

....and what's the purpose of all this? Why couldn't you just write

const char InFile[] = "Air_X/CX.txt";

?
std::ifstream InPutfile;
InPutfile.open(InFile, std::ios::in | std::ios::binary);

return 0;
}

V
 
M

Mike

std::ifstream InPutfile;

here i get the "incomplete type"
compiled before the linux update
 

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,968
Messages
2,570,152
Members
46,697
Latest member
AugustNabo

Latest Threads

Top