Reputation: 6305
okay, I got a few line of code
#include "stdafx.h"
#include "iostream"
#include "conio.h"
#include "string"
#include "windows.h"
environment is visualstudio 8 and I am learning OOP..
what I know so far is (From my previous background of learning so far)
#include<iostream>
will search a file iostream.h
in
standard include library#include"myHeader.h"
will search a file myHeader.h
in the directory where executing file is present, if not found, it will then go to search in standard include librarybased on this, I am much confused, my questions are
thanks for bearing these foolish questions..but confused..:( and even reading different sources makes me more confused,
Edit
Based on first answer,
Please guide me the correct and OPTIMAL way to include header files in my case (sequence, Qoutes and placing .h )
P.S Dont know why, but these files includes correctly, and does not give in error in compiler (visual studio 8)
Upvotes: 0
Views: 1570
Reputation: 145204
#include <iostream>
includes a standard header. A standard header does not need to be a file. It can be retrieved from a database, or be hardwired in the compiler. But of course the usual implementation is that it is a file, and when it is, then it's most likely a file called just “iostream”, not a file called “iostream.h”.
The difference between quotes and angle brackets is that quotes perform an additional search, before (if that's not successful) doing exactly the same as with angle brackets.
In practice, by common convention, the additional search is in the including file's folder.
Do ignore advice about using one or the other form depending on whether files are your own or someone else's.
Use the tools that are suitable for the job at hand.
Upvotes: 2
Reputation: 11
actually as you said, it's fine to use the "" because when the compiler don't find the library in the project folder it will search for it in the standard library. so for these headers <> or "" will do the job just fine, but using <> for standard libraries result in a faster compilation time.
About the .h extension: the new C++ standard uses libraries without .h extension, so when you use <iostream.h>
it will load the old standard library, when using <iostream>
will load the new standard library. so I advise you to use
#include <iostream>
using namespace std;
Upvotes: -1
Reputation: 11116
Going through your questions one by one:
Because whoever wrote this code made a mistake - when using quoted paths instead of angled brackets the search order is suboptimal for library headers. Each of your examples should probably use angled brackets instead.
Whenever you use a library, you should use angled brackets and when you include your own headers you should use quotation marks. The only difference between the two is where the compiler will look for the files. A similar suggestion is actually part of the C++11 standard (16.2§7).
Because those files do not have an extension. When writing #include <iostream>
, the compiler will search for file named exactly iostream
! (Note: This could be implemented differently in other implementations since headers do not technically have to be files at all.)
Most people agree that your own headers should have a .h
, .hpp
or .hh
solution - which one is up to personal preference, but should be used consistently.
Upvotes: 2