-
Problem with #include
Hello,
In my source i include a file tat holds all the includes and
some functions and voids.
Now when my header file named "test.h" has this:
#include <iostream>
void something()
{
cout << "Im printing something" << endl;
}
And i compile it with my source, Im getting error messages
with the void in my header file that are pointing out that
"#include <iostream>" isn't even being used in the header file
I can use it in my source, but not in the header file???
What am i doing wrong?
-
Donīt really understand what you mean. From where I can se you are trying to compile a header file??? In c++ you cannot compile header files just source files.
-
you can't have code/functions in a header file, just definitions of things.
-
So in test.cpp you will have a function
Code:
void print()
{
cout << "something" << endl;
}
and in test.h
you just have the prototype of the print function so
-
(this is my header file)
#include <iostream>
void bla()
{
cout << "bla"; // I can't do this!
}
void bla2()
{
printf("bla"); // But i can do this ?1
}
I'ts like it isnt using iostream in the functions in the header file
(im not compiling the header file, im including it in my source)
-
You need to have this line:
Code:
using namespace std;
under #include <iostream>
If not then each call to cout needs to read:
Code:
std::cout<<"words"<<endl;
-
DOH! Of course , sorry i forgot