C++程序编译为什么错?

vectorsoftwareli 2008-10-18 11:06:46

#include "stdafx.h"
#include<limits>
#include<iostream>
#include<stdio.h>
using std::cout;
using std::endl;
using std::numeric_limits;

int main(int argc, char* argv[])
{
cout<<endl
<<"The range for type short is from"
<<numeric_limits<short>::min()
<<"to"
<<numeric_limits<short>::max();
cout<<endl
<<"The range for type int is from"
<<numeric_limits<int>::min()
<<"to"
<<numeric_limits<int>::max();
cout<<endl
<<"The range for type long is from"
<<numeric_limits<long>::min()
<<"to"
<<numeric_limits<long>::max();
cout<<endl
<<"The range for type float is from"
<<numeric_limits<float>::min()
<<"to"
<<numeric_limits<float>::max();
cout<<endl
<<"The range for type double is from"
<<numeric_limits<double>::min()
<<"to"
<<numeric_limits<double>::max();
cout<<endl
<<"The range for type long double is from"
<<"to"
<<numeric_limits<long double>::max();
cout<<endl;
getchar();
return 0;
}
Compiling...
E:\确定最大值和最小值\确定最大值和最小值.cpp(16) : error C2653: 'numeric_limits<short>' : is not a class or namespace name
...全文
123 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
glacier3d 2008-10-18
  • 打赏
  • 举报
回复
VC2003也没问题
zgjxwl 2008-10-18
  • 打赏
  • 举报
回复
VC6.0加上这句
using namespace std;
zgjxwl 2008-10-18
  • 打赏
  • 举报
回复
#include <limits> 
#include <iostream>
#include <stdio.h>
using std::cout;
using std::endl;
using std::numeric_limits;

int main(int argc, char* argv[])
{
cout <<endl
<<"The range for type short is from"
<<numeric_limits <short>::min()
<<"to"
<<numeric_limits <short>::max();
cout <<endl
<<"The range for type int is from"
<<numeric_limits <int>::min()
<<"to"
<<numeric_limits <int>::max();
cout <<endl
<<"The range for type long is from"
<<numeric_limits <long>::min()
<<"to"
<<numeric_limits <long>::max();
cout <<endl
<<"The range for type float is from"
<<numeric_limits <float>::min()
<<"to"
<<numeric_limits <float>::max();
cout <<endl
<<"The range for type double is from"
<<numeric_limits <double>::min()
<<"to"
<<numeric_limits <double>::max();
cout <<endl
<<"The range for type long double is from"
<<"to"
<<numeric_limits <long double>::max();
cout <<endl;
getchar();
return 0;
}

//编译没问题
//运行结果

The range for type short is from-32768to32767
The range for type int is from-2147483648to2147483647
The range for type long is from-2147483648to2147483647
The range for type float is from1.17549e-038to3.40282e+038
The range for type double is from2.22507e-308to1.79769e+308
The range for type long double is fromto1.79769e+308
baihacker 2008-10-18
  • 打赏
  • 举报
回复
VC9下无问题.
1>------ 已启动生成: 项目: Console, 配置: Debug Win32 ------
1>正在编译...
1>Console.cpp
1>生成日志保存在“file://d:\工程区\VS.NET工程区(9)\Console\Console\Debug\BuildLog.htm”
1>Console - 0 个错误,0 个警告
========== 生成: 成功 1 个,失败 0 个,最新 0 个,跳过 0 个 ==========
sys0003 2008-10-18
  • 打赏
  • 举报
回复
你的VC是什么版本?

我的VS2005编译没问题
sys0003 2008-10-18
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 lishancai 的回复:]
4楼,您好!我用的是VC6.0版,加上using namespace std;编译成功,谢谢您!但是我想请教您一下,为什么我用了using std::cout;
using std::endl;using std::numeric_limits; 这三个语句后还要加using namespace std;?
[/Quote]

你只要using namespace std;就可以了,因为这个就包含所有的std啦
yshuise 2008-10-18
  • 打赏
  • 举报
回复
呵呵
vectorsoftwareli 2008-10-18
  • 打赏
  • 举报
回复
4楼,您好!我用的是VC6.0版,加上using namespace std;编译成功,谢谢您!但是我想请教您一下,为什么我用了using std::cout;
using std::endl;using std::numeric_limits; 这三个语句后还要加using namespace std;?
bfhtian 2008-10-18
  • 打赏
  • 举报
回复
我的vs05下编译也没问题
gamebooks 2008-10-18
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 zgjxwl 的回复:]
VC6.0加上这句

C/C++ codeusing namespace std;
[/Quote]

ccccccccccccccccccccccccccccccccccccc
坐看昀起 2008-10-18
  • 打赏
  • 举报
回复
vc++ 6.0
有问题按楼主的原文件考进去的.如下
--------------------Configuration: c17_c17 - Win32 Debug--------------------
Compiling...
c17_c17.cpp
D:\c++\xiangmu17\c17_c17.cpp(30) : error C2653: 'numeric_limits<short>' : is not a class or namespace name
yangkunjie 2008-10-18
  • 打赏
  • 举报
回复
2008也没问题

65,211

社区成员

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

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