stdlib.h在C++标准库中对应什么头文件?

紫色动力 2010-01-18 11:14:25
RT,谢谢!!
...全文
1194 18 打赏 收藏 转发到动态 举报
写回复
用AI写文章
18 条回复
切换为时间正序
请发表友善的回复…
发表回复
xiuxianshen 2010-04-02
  • 打赏
  • 举报
回复
[Quote=引用 17 楼 purplepower 的回复:]
其实我要的是概括的说明,有什么区别,注意,在哪种情况下用什么的
[/Quote]
C用 #include <stdlib.h>
C++用 #include <cstdlib>
using namespace std;
紫色动力 2010-04-02
  • 打赏
  • 举报
回复
其实我要的是概括的说明,有什么区别,注意,在哪种情况下用什么的
紫色动力 2010-04-02
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 mstlq 的回复:]
引用 8 楼 purplepower 的回复:
引用 6 楼 traceless 的回复:
自己打开不就知道了。。。

站着说话不腰痛

这个,只要打开看看,真的就可以明白很多……

C/C++ code

//
// ISO C++ 14882: 20.4.6 C library
//

#pragma GCC system_header

#include <……
[/Quote]
你这个是在哪打开的?VS里?
zbwzll2 2010-01-21
  • 打赏
  • 举报
回复
#include <stdlib.h>
是包含文件,是C的习惯
#include <cstdlib>
是C++习惯,包含的是头,而不是头文件
jackyjkchen 2010-01-19
  • 打赏
  • 举报
回复
直接打开吧
luhongyu2108 2010-01-19
  • 打赏
  • 举报
回复
#include <cstdlib>
niejimaoo 2010-01-19
  • 打赏
  • 举报
回复
mark
BetterMe 2010-01-19
  • 打赏
  • 举报
回复
这不就是头文件嘛。。。只是一个是C一个是C++
mstlq 2010-01-19
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 purplepower 的回复:]
引用 6 楼 traceless 的回复:
自己打开不就知道了。。。

站着说话不腰痛
[/Quote]
这个,只要打开看看,真的就可以明白很多……

//
// ISO C++ 14882: 20.4.6 C library
//

#pragma GCC system_header

#include <bits/c++config.h>
#include <cstddef>

#ifndef _GLIBCXX_CSTDLIB
#define _GLIBCXX_CSTDLIB 1

#if !_GLIBCXX_HOSTED
// The C standard does not require a freestanding implementation to
// provide <stdlib.h>. However, the C++ standard does still require
// <cstdlib> -- but only the functionality mentioned in
// [lib.support.start.term].

#define EXIT_SUCCESS 0
#define EXIT_FAILURE 1

_GLIBCXX_BEGIN_NAMESPACE(std)

extern "C" void abort(void);
extern "C" int atexit(void (*)());
extern "C" void exit(int);

_GLIBCXX_END_NAMESPACE

#else

#include <stdlib.h>

// Get rid of those macros defined in <stdlib.h> in lieu of real functions.
#undef abort
#undef abs
#undef atexit
#undef atof
#undef atoi
#undef atol
#undef bsearch
#undef calloc
#undef div
#undef exit
#undef free
#undef getenv
#undef labs
#undef ldiv
#undef malloc
#undef mblen
#undef mbstowcs
#undef mbtowc
#undef qsort
#undef rand
#undef realloc
#undef srand
#undef strtod
#undef strtol
#undef strtoul
#undef system
#undef wcstombs
#undef wctomb

_GLIBCXX_BEGIN_NAMESPACE(std)

using ::div_t;
using ::ldiv_t;

using ::abort;
using ::abs;
using ::atexit;
using ::atof;
using ::atoi;
using ::atol;
using ::bsearch;
using ::calloc;
using ::div;
using ::exit;
using ::free;
using ::getenv;
using ::labs;
using ::ldiv;
using ::malloc;
#ifdef _GLIBCXX_HAVE_MBSTATE_T
using ::mblen;
using ::mbstowcs;
using ::mbtowc;
#endif // _GLIBCXX_HAVE_MBSTATE_T
using ::qsort;
using ::rand;
using ::realloc;
using ::srand;
using ::strtod;
using ::strtol;
using ::strtoul;
using ::system;
#ifdef _GLIBCXX_USE_WCHAR_T
using ::wcstombs;
using ::wctomb;
#endif // _GLIBCXX_USE_WCHAR_T

inline long
abs(long __i) { return labs(__i); }

inline ldiv_t
div(long __i, long __j) { return ldiv(__i, __j); }

_GLIBCXX_END_NAMESPACE

#if _GLIBCXX_USE_C99

#undef _Exit
#undef llabs
#undef lldiv
#undef atoll
#undef strtoll
#undef strtoull
#undef strtof
#undef strtold

_GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)

#if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
using ::lldiv_t;
#endif
#if _GLIBCXX_USE_C99_CHECK || _GLIBCXX_USE_C99_DYNAMIC
extern "C" void (_Exit)(int);
#endif
#if !_GLIBCXX_USE_C99_DYNAMIC
using ::_Exit;
#endif

inline long long
abs(long long __x) { return __x >= 0 ? __x : -__x; }

#if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
using ::llabs;

inline lldiv_t
div(long long __n, long long __d)
{ lldiv_t __q; __q.quot = __n / __d; __q.rem = __n % __d; return __q; }

using ::lldiv;
#endif

#if _GLIBCXX_USE_C99_LONG_LONG_CHECK || _GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
extern "C" long long int (atoll)(const char *);
extern "C" long long int
(strtoll)(const char * restrict, char ** restrict, int);
extern "C" unsigned long long int
(strtoull)(const char * restrict, char ** restrict, int);
#endif
#if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
using ::atoll;
using ::strtoll;
using ::strtoull;
#endif
using ::strtof;
using ::strtold;

_GLIBCXX_END_NAMESPACE

_GLIBCXX_BEGIN_NAMESPACE(std)

#if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
using ::__gnu_cxx::lldiv_t;
#endif
using ::__gnu_cxx::_Exit;
using ::__gnu_cxx::abs;
#if !_GLIBCXX_USE_C99_LONG_LONG_DYNAMIC
using ::__gnu_cxx::llabs;
using ::__gnu_cxx::div;
using ::__gnu_cxx::lldiv;
#endif
using ::__gnu_cxx::atoll;
using ::__gnu_cxx::strtof;
using ::__gnu_cxx::strtoll;
using ::__gnu_cxx::strtoull;
using ::__gnu_cxx::strtold;

_GLIBCXX_END_NAMESPACE

#endif // _GLIBCXX_USE_C99

#ifdef __GXX_EXPERIMENTAL_CXX0X__
# if defined(_GLIBCXX_INCLUDE_AS_TR1)
# error C++0x header cannot be included from TR1 header
# endif
# if defined(_GLIBCXX_INCLUDE_AS_CXX0X)
# include <tr1_impl/cstdlib>
# else
# define _GLIBCXX_INCLUDE_AS_CXX0X
# define _GLIBCXX_BEGIN_NAMESPACE_TR1
# define _GLIBCXX_END_NAMESPACE_TR1
# define _GLIBCXX_TR1
# include <tr1_impl/cstdlib>
# undef _GLIBCXX_TR1
# undef _GLIBCXX_END_NAMESPACE_TR1
# undef _GLIBCXX_BEGIN_NAMESPACE_TR1
# undef _GLIBCXX_INCLUDE_AS_CXX0X
# endif
#endif

#endif // !_GLIBCXX_HOSTED

#endif
紫色动力 2010-01-18
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 traceless 的回复:]
自己打开不就知道了。。。
[/Quote]
站着说话不腰痛
飞天御剑流 2010-01-18
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 purplepower 的回复:]
引用 1 楼 xboy 的回复:
#include <cstdlib>

到底有什么区别呢?老书用的都是“stdlib.h”
[/Quote]

stdlib.h是引入命名空间前的头文件,cstdlib是引入命名空间后的头文件,cstdlib把stdlib.h中的接口和实现都包含在命名空间std里面。
traceless 2010-01-18
  • 打赏
  • 举报
回复
自己打开不就知道了。。。
xboy 2010-01-18
  • 打赏
  • 举报
回复
其实标准的版本不同
在使用上都支持
紫色动力 2010-01-18
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 xboy 的回复:]
#include <cstdlib>
[/Quote]
到底有什么区别呢?老书用的都是“stdlib.h”
yunyun050924 2010-01-18
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 traceless 的回复:]
#include <cstdlib>
[/Quote]
个哈哈
traceless 2010-01-18
  • 打赏
  • 举报
回复
#include <cstdlib>
xboy 2010-01-18
  • 打赏
  • 举报
回复
#include <cstdlib>

64,646

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧