error: variable ‘std::ifstream fin’ has initializer but incomplete type

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <iostream>
using namespace std;
enum BOOL { FALSE , TRUE };

int main(int argc, char**argv) //returns 1 on error
{
	if(argc != 2)
	{
	cout << "Usage: argv[0] <infile>\n";
	return(1);
	}

//open the input stream
ifstream fin (argv[1], ios::binary);
if(!fin)
{
	cout << "Unable to open " << argv[1] << " for reading.\n";
	return (1);
}
char ch;
while (fin.get(ch))
	if ((ch > 32 && ch <127) || ch == '\n' || ch == 't')
cout << ch;
fin.close();
}


and i get this error
error: variable ‘std::ifstream fin’ has initializer but incomplete type


Does any one know why?
Don't forget to #include <fstream> !!! ;)
Last edited on
Thanks, but I have another problem, now the output is:
Usage: argv[0] <infile>

It doesn't let me even enter anuthing :(
You aren't passing any command line arguments.
How do I do that?
I'm running Ubuntu Linux and from the command line I do: g++ <filename> -o test
then: ./test
then i get the "Usage: argv[0] <infile>" message , but how do i pass command line arguments?
./test <command line arguments>
I did: ./test testFile ch17_name.cpp
and still got: Usage: argv[0] <infile>
The name of the program is the first argument, so you're giving 3 when you expect 2.
Don't just copy paste
Thanks that worked fine :)
Last edited on
Topic archived. No new replies allowed.