LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   makefile include <iostream.h> question (https://www.linuxquestions.org/questions/linux-newbie-8/makefile-include-iostream-h-question-4175423195/)

HarryBoy 08-21-2012 05:27 AM

makefile include <iostream.h> question
 
I'm trying to learn makefiles and have started here:
http://mrbook.org/tutorials/make/

I get the following error:

Code:

myLinuxBox:/home/user/makefiles # g++ main.cpp hello.cpp factorial.cpp -o hello
main.cpp:1:22: error: iostream.h: No such file or directory
main.cpp: In function âint main()â:
main.cpp:6: error: âcoutâ was not declared in this scope
main.cpp:6: error: âendlâ was not declared in this scope
hello.cpp:1:22: error: iostream.h: No such file or directory
hello.cpp: In function âvoid print_hello()â:
hello.cpp:5: error: âcoutâ was not declared in this scope

The main.cpp is simply:

Code:

#include <iostream.h>
#include "functions.h"

int main(){
    print_hello();
    cout << endl;
    cout << "The factorial of 5 is " << factorial(5) << endl;
    return 0;
}


How do I include the iostream.h properly??

gregAstley 08-21-2012 05:31 AM

Quote:

Originally Posted by HarryBoy (Post 4759943)
I'm trying to learn makefiles and have started here:
http://mrbook.org/tutorials/make/

I get the following error:

Code:

myLinuxBox:/home/user/makefiles # g++ main.cpp hello.cpp factorial.cpp -o hello
main.cpp:1:22: error: iostream.h: No such file or directory
main.cpp: In function âint main()â:
main.cpp:6: error: âcoutâ was not declared in this scope
main.cpp:6: error: âendlâ was not declared in this scope
hello.cpp:1:22: error: iostream.h: No such file or directory
hello.cpp: In function âvoid print_hello()â:
hello.cpp:5: error: âcoutâ was not declared in this scope

The main.cpp is simply:

Code:

#include <iostream.h>
#include "functions.h"

int main(){
    print_hello();
    cout << endl;
    cout << "The factorial of 5 is " << factorial(5) << endl;
    return 0;
}


How do I include the iostream.h properly??

have you tried simply #include <iostream> ?
i.e. leave out the ".h"

HarryBoy 08-21-2012 05:36 AM

Thanks for your reply. I did this and it does not complain about not finding it but it complains on the cout:


Quote:

main.cpp: In function âint main()â:
main.cpp:6: error: âcoutâ was not declared in this scope
main.cpp:6: error: âendlâ was not declared in this scope
Any other ideas??

gregAstley 08-21-2012 05:42 AM

Quote:

Originally Posted by HarryBoy (Post 4759948)
Thanks for your reply. I did this and it does not complain about not finding it but it complains on the cout:




Any other ideas??

ah yes...cout is in the std namespace so in order to use it you have to specify the namespace, for example: std::cout << "blah";
You can also import the name space entirely (bad idea usually) by
using namespace std; in which case you don't need the "std::" prefix. You can also import individual elements from the namespace (better than getting all of them) by
using std::cout; (and again you can then drop the prefix)

HarryBoy 08-21-2012 06:23 AM

excellent, thanks :)


All times are GMT -5. The time now is 07:18 PM.