vs. vs. “iostream.h”

2020-01-27 05:38发布

When including a header file in C++, what's the difference between...

1) including the .h versus not including the .h when wrapping it in < > signs?

#include <iostream> vs. #include <iostream.h>

2) wrapping the header name in double quotes versus wrapping it in < > signs?

#include <iostream.h> vs. #include "iostream.h"

Thanks in advance!

标签: c++ iostream
8条回答
可以哭但决不认输i
2楼-- · 2020-01-27 06:38

The simple answer to the first answer is that iostream.h doesn't exist, at least in the GCC implementation. If you're on *nix, type

% locate iostream.h
/usr/include/c++/3.4.3/backward/iostream.h

and

% locate iostream
/usr/include/c++/3.4.3/iostream
/usr/include/c++/3.4.3/backward/iostream.h

As Zee's article says, iostream.h is for backward compatibility.

查看更多
我命由我不由天
3楼-- · 2020-01-27 06:39

In short:

iostream.h is deprecated - it is the original Stroustrup version, and iostream is the version from the standards committee. Generally compilers point them both to the same thing, but some older compilers won't have the older one. In some odd cases they will both exist and be different (to support legacy code) and you then must be specific.

"" versus <> simply means check the local directories for the header before going to the library (in most compilers).

-Adam

查看更多
登录 后发表回答