main.cpp: In function `bool readfile(char*)':
main.cpp:12: aggregate `std::ifstream infile' has incomplete type and cannot be
defined
make.exe: *** [main.o] Error 1
Execution terminated
Any ideas on how I might fix this? I'm really excited about using Dev-C++ but I'm really surprised at some of the errors that it has on a default installation. These should be fairly easy to fix in the build so that newbies like myself don't have to do a lot of tweaking just to be able to compile one-liners.
Thanks,
Carl Youngblood
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Well, in this case, the errors are in YOUR code.
(Maybe you ought to be a LITTLE more careful before blaming the compiler) There are two rather glaring errors in your code.
(1) You forgot to include fstream (no, iostream does not get you there)
(2) You have the variable filename which appears from nowhere. (i.e. never declared or given a value).
A minor error, you will not pause on your error condition. I did not mess with your filename (I took it out), but this compiles and works.
Not waste of time, I learn something with every problem I solve.
The point I was trying to make, that I was far to blunt in making is this: It is just dangerous to get a....habit...of thinking when something does not compile or run right, that something is wrong with the tool.
I don't know about anyone else, but for me, 999 times out of 1000, it is my mistake, not a problem with the compiler. Yes, I make many mistakes.
Wayne
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I'm having a really annoying problem and I can't figure out what's wrong. When I try to compile the following simple file:
#include <iostream>
#include <stdlib.h>
using namespace std;
int main(int argc, char *argv[])
{
ifstream infile("test.txt");
if (!infile)
{
cerr << "Error opening " << filename << " for input." << endl;
exit(1);
}
infile.close();
system("PAUSE");
return 0;
}
I get the following error message:
Compiler: Default compiler
Building Makefile: "C:\Source\CPlusPlus\coins\Makefile.win"
Executing make...
make.exe -f "C:\Source\CPlusPlus\coins\Makefile.win" all
g++.exe -c main.cpp -o main.o -I"C:/Dev-Cpp/include" -I"C:/Dev-Cpp/include/c++" -I"C:/Dev-Cpp/include" -I"C:/Dev-Cpp/include/c++/mingw32" -I"C:/Dev-Cpp/include/c++/backward"
main.cpp: In function `bool readfile(char*)':
main.cpp:12: aggregate `std::ifstream infile' has incomplete type and cannot be
defined
make.exe: *** [main.o] Error 1
Execution terminated
Any ideas on how I might fix this? I'm really excited about using Dev-C++ but I'm really surprised at some of the errors that it has on a default installation. These should be fairly easy to fix in the build so that newbies like myself don't have to do a lot of tweaking just to be able to compile one-liners.
Thanks,
Carl Youngblood
Well, in this case, the errors are in YOUR code.
(Maybe you ought to be a LITTLE more careful before blaming the compiler) There are two rather glaring errors in your code.
(1) You forgot to include fstream (no, iostream does not get you there)
(2) You have the variable filename which appears from nowhere. (i.e. never declared or given a value).
A minor error, you will not pause on your error condition. I did not mess with your filename (I took it out), but this compiles and works.
Enjoy,
Wayne
#include <iostream>
#include <stdlib.h>
#include <fstream>
#include <string>
using namespace std;
int main(int argc, char *argv[])
{
ifstream infile("waktester.txt");
if (!infile)
{
cerr << "Error opening for input." << endl;
system("PAUSE");
exit(1);
}
infile.close();
cout << "Got the sucker!\n";
system("PAUSE");
return 0;
}
So sorry! my bad... I really should have looked a little harder before posting. Sorry to waste your time.
Carl
Not waste of time, I learn something with every problem I solve.
The point I was trying to make, that I was far to blunt in making is this: It is just dangerous to get a....habit...of thinking when something does not compile or run right, that something is wrong with the tool.
I don't know about anyone else, but for me, 999 times out of 1000, it is my mistake, not a problem with the compiler. Yes, I make many mistakes.
Wayne