C ++标准库的(其余部分)未涵盖C标准库的哪些部分?

时间:2014-03-08 12:32:55

标签: c++ c++11 c++-standard-library

  

The C++ library includes the same definitions as the C language library

但是C ++库似乎在非C库头中复制(/扩展)C库的一些功能。例如,C库具有< string.h>,并且C ++库具有< cstring>和< string&gt ;; C库具有< time.h&gt ;,并且C +库具有< ctime>和< chrono>。

如果我需要一个字符串类,我假设我最好使用< string>而不是< cstring>,因为< string>可以受益于C ++中的所有非C功能(例如异常)。但是C库中的功能在C ++库中不存在于任何其他形式。例如,我在< cstring>之外找不到像memcpy和memcmp这样的东西。

C库的哪些部分在非C库标题中没有类似物?

(如果C ++标准的版本对此很重要,我对C ++ 11很感兴趣。)

1 个答案:

答案 0 :(得分:12)

没有那么多标题,所以我们只列出它们。有些可以用语言设施代替,而不是库。 (我没有枚举每个头文件中的每个函数,所以我可能错过了大多数同事没有C ++替代品的奇怪函数。)

C library         C++ alternatives
assert.h          Exceptions
complex.h         <complex>
ctype.h           None (or maybe <locale>, if you want to jump down that rabbit-hole)
errno.h           None (but only applies to C functions)
fenv.h            None
float.h           <limits>
inttypes.h        (See breakdown)
   formatting     <iostream>
   strto...       <string> (C++11), <sstream>
   imaxabs        std::abs overloads
   imaxdiv        std::div overloads
iso646.h          Language
locale.h          <locale>
math.h            None (extended with C++ overloads)
setjmp.h          Exceptions
signal.h          None
stdarg.h          Variadic templates (C++11)
stdbool.h         Language
stddef.h          None
stdint.h          None
stdio.h           <iostream> etc.
stdlib.h          (See breakdown)
   atof etc.      <sstream>, <string> (C++11)
   rand etc.      <random> (C++11)
   malloc etc.    new, containers
   abort etc.     None
   bsearch etc.   <algorithm>
   abs etc.       None (extended with C++ overloads)
   mb strings     None
string.h          <string>, <algorithm>
tgmath.h          <cmath> (C++ overloads)
time.h            <chrono> (C++11)
wchar.h           <iostream> etc.
wctype.h          None

总结:

  

C库的哪些部分在非C库标题中没有类似物?

[w]ctype.herrno.hfenv.hfenv.hmath.hsignal.hstddef.hstdint.h ,一些stdlib.h。在C ++ 11之前,还有stdarg.htime.h和更多stdlib.h