LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-21-2012, 06:27 AM   #1
HarryBoy
Member
 
Registered: Apr 2008
Distribution: MontaVista Linux Version 4.0.1, Professional Edition
Posts: 215

Rep: Reputation: 16
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??
 
Old 08-21-2012, 06:31 AM   #2
gregAstley
LQ Newbie
 
Registered: Aug 2012
Distribution: ubuntu 11.10
Posts: 27

Rep: Reputation: 4
Quote:
Originally Posted by HarryBoy View Post
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"
 
Old 08-21-2012, 06:36 AM   #3
HarryBoy
Member
 
Registered: Apr 2008
Distribution: MontaVista Linux Version 4.0.1, Professional Edition
Posts: 215

Original Poster
Rep: Reputation: 16
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??
 
Old 08-21-2012, 06:42 AM   #4
gregAstley
LQ Newbie
 
Registered: Aug 2012
Distribution: ubuntu 11.10
Posts: 27

Rep: Reputation: 4
Quote:
Originally Posted by HarryBoy View Post
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)
 
Old 08-21-2012, 07:23 AM   #5
HarryBoy
Member
 
Registered: Apr 2008
Distribution: MontaVista Linux Version 4.0.1, Professional Edition
Posts: 215

Original Poster
Rep: Reputation: 16
excellent, thanks
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to include my helloworld.c into makefile? dennisdd Linux - Newbie 7 10-19-2011 04:39 AM
my iostream.h include won't work slinky2004 Programming 5 09-20-2005 01:37 AM
GCC:- 'cout' is an undeclared function when #include <iostream> is included? caesius_01 Programming 5 04-04-2004 12:00 PM
g++ why cant i #include \<iostream\> ??? qwijibow Programming 4 10-03-2003 08:17 AM
#include <iostream> ERROR alexrm1x Programming 9 03-14-2003 11:04 AM


All times are GMT -5. The time now is 02:19 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration