Hello. I'am a C++ Beginner.
I'am using:
CodeBlocks 10.05
mingw32-g++.exe as C++ Compiler.
Windows 7
When I try to include my self made header file YourName.h into my "hello world"-Application then the Debugger says:
Compiling: main.cpp
D:\C++ Exercise\Fehler\main.cpp:4: error: expected unqualified-id before 'using'
D:\C++ Exercise\Fehler\main.cpp: In function 'int main()':
D:\C++ Exercise\Fehler\main.cpp:8: error: 'cout' was not declared in this scope
D:\C++ Exercise\Fehler\main.cpp:8: error: 'endl' was not declared in this scope
Process terminated with status 1 (0 minutes, 0 seconds)
3 errors, 0 warnings
When I remove the line #inlude "YourName.h" then the debugger will not release any error message.
I already checked many topics in other forums but didn't find anything helpful.
Here is the Code of...
main.cpp
#include <iostream>
#include "YourName.h"
using namespace std;
int main()
{
cout << "Hello world!" << endl;
return 0;
}
YourName.h
#ifndef YOURNAME_H_INCLUDED
#define YOURNAME_H_INCLUDED
struct Insect {
Insect () {Legs = 6;};
int Legs;
}
#endif // YOURNAME_H_INCLUDED
What am I doing wrong?
Even adding "std::" in front of cout or endl; won't help and cause further errors.
Please help me. Thanks
note that this is NOT a general programmers learning forum, but a forum related on using CB.
But I will help you this once.
First : it is the compiler complaining about your code, since it is incorrect, and not the debugger.
Your mistake is that you need a ";" after the closing brace of your struct definition
struct Insect
{
Insect () : mLegs(6) {}
int mLegs;
};
Note also the other style enhancements I did;