验证using namespace std

eric432 2007-01-15 02:48:04
#include <cmath>
#include <stdio.h>
using namespace std;

int main()
{
double a = 2;
double b = cos(a);
printf("b=%f",b);

return 0;
}

错误信息:
D:\ftp\11\11.cpp(3) : error C2871: 'std' : does not exist or is not a namespace
Error executing cl.exe.

这样是不是说明#include<cmath>不需要using namespace std??????
只有#include <iostream>才需要using namespace std?
我用的是vc6
...全文
283 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
OOPhaisky 2007-01-15
  • 打赏
  • 举报
回复
错误信息:
D:\ftp\11\11.cpp(3) : error C2871: 'std' : does not exist or is not a namespace
Error executing cl.exe.

这样是不是说明#include<cmath>不需要using namespace std??????
只有#include <iostream>才需要using namespace std?
------------------------------------------------------------------------------------
这并不说明“#include<cmath>不需要using namespace std;只有#include <iostream>才需要using namespace std”,只能说明你的编译器比较落后,还不支持std。
discory 2007-01-15
  • 打赏
  • 举报
回复
怎么看出用没用std空间的
lann64 2007-01-15
  • 打赏
  • 举报
回复
这是VC6实现的问题。
gcc实现里,cmath是使用了std空间的。
gjw310 2007-01-15
  • 打赏
  • 举报
回复
支持
(瞌睡虫·星辰)
eric432 2007-01-15
  • 打赏
  • 举报
回复
谢谢各位大哥
收获颇多。。
todototry 2007-01-15
  • 打赏
  • 举报
回复
它们都属于std名字空间
jixingzhong 2007-01-15
  • 打赏
  • 举报
回复
#include <cmath>
#include <stdio.h>
==》
#include <math.h> //头文件风格一致
#include <stdio.h>
jixingzhong 2007-01-15
  • 打赏
  • 举报
回复
程序中没有使用到 std 名字空间中的内容,
可以 去掉 using namespace std
cubety 2007-01-15
  • 打赏
  • 举报
回复

Include the standard header <cmath> to effectively include the standard header <math.h> within the std namespace.
huangyangman 2007-01-15
  • 打赏
  • 举报
回复
// cmath standard header

#if _MSC_VER > 1000
#pragma once
#endif

#ifndef _CMATH_
#define _CMATH_
#ifdef _STD_USING
#undef _STD_USING
#include <math.h>
#define _STD_USING
#else
#include <math.h>
#endif /* _STD_USING */
#endif /* _CMATH_ */

根本没用到std命名空间,#include<cmath>自然不需要using namespace std

65,208

社区成员

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

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