iostream
vsなどの違いに関する情報を見てきましたiostream.h
。それらから私が集めたものから、それらの違いは、.h
拡張子のないバージョンは名前空間にデータを入力しないのに対し、拡張子のあるバージョンは名前空間にデータを入力することです。
cmath
これはvsでも同じmath.h
ですか? なぜcmath
(およびそれに似た他の多くのファイル) のc
代わりに、接頭辞が付いているのmath
ですか? それらの間にもっと違いがありますか?
I've seen some information about differences between things like iostream vs iostream.h.
[iostream.h] is not a standard header.
it is not an example of the issue you're raising.
[cmath] defines symbols in the std
namespace, and may also define symbols in the global namespace. [math.h] defines symbols in the global namespace, and may also define symbols in the std
namespace. if you include the former and use an unqualified symbol, it may compile with one compiler but not with another. therefore it's a good idea to use [math.h]. and in general, for such header pairs, to use the [.h] version.
c++98 provided a formal guarantee of the cxxx
header not polluting the global namespace. maybe that was why they were defined. however, that was a bit harder to implement than polluting ones, so in practice no standard library implementation that i know of followed the standard in this respect, and so it was finally changed to reflect reality in c++11.
名前が で始まるc
ヘッダーは、C 標準ライブラリのヘッダーから派生したものです。c
プレフィックスが削除され、サフィックスが追加された対応するヘッダーは.h
、C 標準ライブラリ ヘッダーと同一 (またはほぼ同一) です。
<cmath>
std
名前空間の下に関連するシンボルを定義します。<math.h>
それらをグローバルに定義します。
(私はそれがそれほど単純ではないことを学びました.Alfの答えを見てください。)
<cmath>
また、すべての<cxxx>
ヘッダーは標準 C++ です。つまり、C++ 標準で概説されているように、それらのヘッダーでサポートされているものと、それらの関数がどのように機能するかについて強力な保証があります。std
名前空間で一連の関数を定義するだけです。
<math.h>
すべての主要な実装でサポートされているにもかかわらず、<xxx.h>
ヘッダーは標準 C++ ではありません。ただし、これらは非推奨であるため、実装に含める場合、これらのヘッダーの内容は保証されません。実際、特定の実装では、バージョンとは異なる<cxxx>
動作をする関数が提供されていることが観察されています。
したがって、<cxxx>
C++ を記述するときは常に を使用し、関数の名前を で修飾する必要がありstd::
ますstd::malloc
。