iostream.h header file absent

Asked by athulrajktr

I wanna compile & run a C++ program.
Eg
                      #include <iostream.h>
                        int main (void)
                      {
                     cout << "Hello World\n";
                       }

 But gcc says iostream.h is absent. How can I write a program without iostream.h. How to overcome this?

Question information

Language:
English Edit question
Status:
Solved
For:
Ubuntu Edit question
Assignee:
No assignee Edit question
Solved by:
joey.blacksmith
Solved:
Last query:
Last reply:
Revision history for this message
actionparsnip (andrew-woodhead666) said :
#1

sudo apt-get install build-essential

Revision history for this message
actionparsnip (andrew-woodhead666) said :
#2

btw, if you use:

void main (void)

you don't have to have the silly return 0 on the end ;)

Revision history for this message
joey.blacksmith (joey-blacksmith) said :
#3

What about changing "<iostream.h>" to "<iostream>" ?

Revision history for this message
athulrajktr (athulrajktr) said :
#4

changrd "<iostream.h>" to "<iostream>" & compiled
Result:
test.cpp: In function ‘int main()’:
test.cpp:4: error: ‘cout’ was not declared in this scope

Revision history for this message
actionparsnip (andrew-woodhead666) said :
#5

you need:

return 1

in the main part as you have defined main as returning int.

Revision history for this message
Best joey.blacksmith (joey-blacksmith) said :
#6

Well man, you need to add line "using namespace std;" after "#include<iostream>" or you can add "std::" right before cout command... (std::cout<<"Hello world\n";)

Revision history for this message
athulrajktr (athulrajktr) said :
#7

thank you joey.
Also, why is this so?
what about "cin" command?
I can't get sin , cos ,... math functions using math.h

Revision history for this message
actionparsnip (andrew-woodhead666) said :
#8

If you use:

#include <iostream>
using namespace std;
void main()
{
  cout << "Hello World\n";
}

Then you avoid it

for cin use something like:

#include <iostream>
using namespace std;
void main()
{
  int age;
  cout << "Please tell me your age : ";
  cin >> age
  cout << "You are " << age*365 << " days old!" << endl;
}

Oh takes me back....

Revision history for this message
athulrajktr (athulrajktr) said :
#9

Thanks joey.blacksmith, that solved my question.

Revision history for this message
J. Brent Coats (jbcoats) said :
#10

I get the following error when trying to compile a cpp program:
  in function main:
  undefined reference to 'std::cout'
What am I missing?