Click here to Skip to main content
15,884,628 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In this code if i write iostream.h then it will give me output without any error, but if i write only
iostream in place of iostream.h then i will have to use namespace std statement ,then what is the use of iostream.h headerfile ?

C++
#include <iostream>
#include <conio.h>

//using namespace std;
int main()
{
    //std::cout<<"Hello";
    
    cout<<"Hello";
    getch();
    return 0;
}
Posted
Updated 23-Oct-11 9:03am
v5
Comments
Sergey Alexandrovich Kryukov 21-Oct-11 21:59pm    
The code you show will not compile, but this is because you need to escape <>. Also, put it all in <pre lang="c++">....</pre>.
--SA

You say it like namespace-qualified names or "using namespace std" is something bad. :-)

This is good! What do you think name spaces are designed for?

The background on "extensionless" "<iostream>" vs. "<iostream.h>" is explained in detail here: http://members.gamedev.net/sicrane/articles/iostream.html[^].

—SA
 
Share this answer
 
v3
Comments
Espen Harlinn 23-Oct-11 19:24pm    
Good points :)
Sergey Alexandrovich Kryukov 23-Oct-11 20:11pm    
Thank you, Espen.
--SA
#include <iostream.h>
is the now obsolete header file for the iostream stuff.

Now, you juste need to include

C++
#include <iostream>


the iostream without the .h is the standardized header for the iostreams.

All new standard c++ header use the .h-less names.

#include <vector>
#include <algorithm>
...


Today all (most?) STL and standard C++ code are in the std namespace.

You can either use

using namespace std;


to let the compiler (?) know to look in the std namespace if it cannot find the declaration in the global namespace. (probably a bad wording).

or just use std:: in front of the STL and standard c++ functions and method.

so you'll have
C++
...
using namespace std;
cout << "hello" << endl;


or

C++
...
std::cout << "hello" << std::end;
 
Share this answer
 
v3
Comments
Espen Harlinn 23-Oct-11 19:25pm    
Nice effort :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900