iostream.h help

Asked by COKEDUDE

Which package or library do we need to use iostream.h in c++ programs? I tried to compile a c++ here with no luck. The first fraction one.

http://www.cplusplus.com/src/
http://www.cplusplus.com/files/fraction.zip

~ $ g++ -Wall /home/mint/Downloads/Fraction.cpp
/home/mint/Downloads/Fraction.cpp:8: fatal error: iostream.h: No such file or directory
compilation terminated.

I have the g++, g++-4.3, g++-4.4, and g++-4.5
http://packages.ubuntu.com/search?keywords=g%2B%2B&searchon=names&suite=maverick&section=all

Question information

Language:
English Edit question
Status:
Answered
For:
Ubuntu gcc-defaults Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
mycae (mycae) said :
#1

C++ STL headers do not have the .h extension

your code might look like

#include <iostream>
#include <cstdlib>

using std::cout;
using std::endl;

int main()
{
    cout << "hello cokedude" << endl;

}

Revision history for this message
mycae (mycae) said :
#2

That source code is very c-ish, and quite wrong C++. It might compile under visual studio, but any sane compiler would reject that.

1) Dont use /*...*/ for single line comments

2) cout and endl are members of the std:: namespace

Revision history for this message
COKEDUDE (cokedude) said :
#3

Yea your right with your first post. Just needed to remove the .h.

#include <iostream>

As for your second post that is not always correct. I have a centos system and it compiles it. Any idea why my centos system compiles this?

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

It shouldn't; it means that one of the headers has imported the std namespace incorrectly. The whole point of std:: was to reduce the name-collision problem (oh you want a doitNow() function too? Sorry -- names taken!)

/**/ is not wrong, it just doesn't nest, so is really annoying when you want to /**/ out a larger block.

Can you help with this problem?

Provide an answer of your own, or ask COKEDUDE for more information if necessary.

To post a message you must log in.