c++ cmath的函数为什么在vs中加std不会错

u012658548 2013-11-11 08:16:19
在vc++ 6.0为什么会这样
#include<iostream>
#include<cmath>
int main()
{
int a=std::sqrt(4);
std::cout<<a<<"\n";
}
报错 error C2039: 'sqrt' : is not a member of 'std
...全文
329 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
Adol1111 2013-11-12
  • 打赏
  • 举报
回复
引用 5 楼 u012658548 的回复:
6.0里面cmath也可以的
我刚刚查了下好像都是说VC6的cmath之类C语言库实现有问题,没有放到std下,VS上已经修复了,你用math.h吧或者直接用sqrt试试看
Adol1111 2013-11-12
  • 打赏
  • 举报
回复
我刚刚查了下好像都是说VC6的cmath之类C语言库实现有问题,没有放到std下,VS上已经修复了,你用math.h吧或者直接用sqrt试试看
u012658548 2013-11-12
  • 打赏
  • 举报
回复
6.0里面cmath也可以的
漫步者、 2013-11-12
  • 打赏
  • 举报
回复
6.0里面是math.h
赵4老师 2013-11-12
  • 打赏
  • 举报
回复
C:\Program Files\Microsoft Visual Studio 10.0\VC\include\cmath
// cmath standard header
#pragma once
#ifndef _CMATH_
#define _CMATH_
#include <yvals.h>

#ifdef _STD_USING
 #undef _STD_USING
  #include <math.h>
 #define _STD_USING

#else /* _STD_USING */
 #include <math.h>
#endif /* _STD_USING */

 #if _GLOBAL_USING && !defined(RC_INVOKED)

_STD_BEGIN
using _CSTD acosf; using _CSTD asinf;
using _CSTD atanf; using _CSTD atan2f; using _CSTD ceilf;
using _CSTD cosf; using _CSTD coshf; using _CSTD expf;
using _CSTD fabsf; using _CSTD floorf; using _CSTD fmodf;
using _CSTD frexpf; using _CSTD ldexpf; using _CSTD logf;
using _CSTD log10f; using _CSTD modff; using _CSTD powf;
using _CSTD sinf; using _CSTD sinhf; using _CSTD sqrtf;
using _CSTD tanf; using _CSTD tanhf;

using _CSTD acosl; using _CSTD asinl;
using _CSTD atanl; using _CSTD atan2l; using _CSTD ceill;
using _CSTD cosl; using _CSTD coshl; using _CSTD expl;
using _CSTD fabsl; using _CSTD floorl; using _CSTD fmodl;
using _CSTD frexpl; using _CSTD ldexpl; using _CSTD logl;
using _CSTD log10l; using _CSTD modfl; using _CSTD powl;
using _CSTD sinl; using _CSTD sinhl; using _CSTD sqrtl;
using _CSTD tanl; using _CSTD tanhl;

using _CSTD abs;

using _CSTD acos; using _CSTD asin;
using _CSTD atan; using _CSTD atan2; using _CSTD ceil;
using _CSTD cos; using _CSTD cosh; using _CSTD exp;
using _CSTD fabs; using _CSTD floor; using _CSTD fmod;
using _CSTD frexp; using _CSTD ldexp; using _CSTD log;
using _CSTD log10; using _CSTD modf; using _CSTD pow;
using _CSTD sin; using _CSTD sinh; using _CSTD sqrt;
using _CSTD tan; using _CSTD tanh;
_STD_END
 #endif /* _GLOBAL_USING */

#endif /* _CMATH_ */

/*
 * Copyright (c) 1992-2009 by P.J. Plauger.  ALL RIGHTS RESERVED.
 * Consult your license regarding permissions and restrictions.
V5.20:0009 */
lunat 2013-11-11
  • 打赏
  • 举报
回复
没有试过,如果确实是这样的话,就是VC6太老了,头文件不够完善。 而且标准上面好像没有规定cmath导出的函数必须声明到std命名空间下(不确定?)。
Adol1111 2013-11-11
  • 打赏
  • 举报
回复
VC6好像没有cmath...毕竟VC6是C++标准出来前开发的,可能C语言库还是比较老的。你换成math.h吧,或者换新的编译器。

64,654

社区成员

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

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