Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ includes with and without .h [duplicate]

Tags:

Possible Duplicate:
What is the difference between using #include<filename> and #include<filename.h> in c++

I've never noticed it making any difference whether or not I include the .h at the end of an include, so I've always ignored the meaning, but I've just noticed in a particular program of mine, I get the error "memcpy was not declared in this scope" if I include "string", but not if I include "string.h".

First of all, I was wondering the specific cause of this, but also generally the difference between the two. At the same time, if someone could explain the difference between includes in angular brackets and those in quotation marks, It'd be much appreciated.

like image 247
wyatt Avatar asked May 10 '10 00:05

wyatt


People also ask

What happens if header file is included twice in C?

If a header file happens to be included twice, the compiler will process its contents twice. This is very likely to cause an error, e.g. when the compiler sees the same structure definition twice. Even if it does not, it will certainly waste time. This construct is commonly known as a wrapper #ifndef.

Is it necessary to include header file in C?

In C program should necessarily contain the header file which stands for standard input and output used to take input with the help of scanf() and printf() function respectively.

Should .h or .cpp include?

The includes in the . c are only included when that one file is compiled, but the includes for the . h have to be included by every file that uses it.

Can C program successfully without including header files?

Yes you can wirte a program without #include , but it will increase the complexity of the programmer means user have to write down all the functions manually he want to use.It takes a lot of time and careful attention while write long programs.


1 Answers

<string> is the C++ standard library string header file containing std::string and its friends. <string.h> is a different header, from the C standard library, which has functions for manipulating C strings (null-terminated strings) and other related functions.

The two are entirely different and unrelated. In C++ (as in C), a header file can have any extension. The C++ standard library headers have no extension; the C standard library headers have a .h extension. .hpp or .hxx are also common.

like image 196
James McNellis Avatar answered Nov 04 '22 03:11

James McNellis