0

DUPLICATE:
When can you omit the file extension in an #include directive?


I feel a little cleverer after finding:
What is the difference between #include <filename> and #include "filename"?

But in my code I use #include <string>.
string is not a valid filename and the angle brackets are not put in "".

Is this a third way of including other files or how do I have to understand this?
In other words, what is <string>?

Community
  • 1
  • 1
Noel Widmer
  • 4,444
  • 9
  • 45
  • 69

2 Answers2

2

string is not a valid filename

It is. The name of the header file is literally string. Search your include paths, e. g.:

find /usr/include /usr/local/include -name "string"

and you will have some results.

  • Do you know why someone would/should name their file just string? Seems very weird, but there certainly is a reason... – Noel Widmer Jun 10 '15 at 09:28
  • 2
    @NoelWidmer The reason is that the C++ standard says that it should be called `string`. – The Paramagnetic Croissant Jun 10 '15 at 09:28
  • 1
    Please note that you should absolutely avoid naming your own files in that way. It is only standardized for the standard headers. The new naming scheme of header files does not necessarily mean that the filenames of standard header files have no extension from the point of view of the operating system. How include statements for standard header files are handled is implementation defined. C++ systems might add an extension or even use build-in declarations without reading a file. In practice however those files mostly have this name for simplicity. – Andy Reimann Jun 10 '15 at 10:37
  • I am reading a pdf right now and found the following link in it: http://stackoverflow.com/questions/441568/when-can-you-omit-the-file-extension-in-an-include-directive/441683#441683 – Noel Widmer Jun 10 '15 at 14:00
0

What are file extensions?

They are some OS (popularly windows ) own way to identify file type to use its default app to open it. Whereas Mac and Linux use MIME for identification of file type.

“MIME” stands for Multipurpose Internet Mail Extensions

So in this case of library its the same. It is made using MIME type and since our windows os dont need to open that file other than a using specific IDE we are saved form a problem of file identification.

Sagar Kar
  • 177
  • 1
  • 2
  • 10