numeric_limits::min() (如何求一个类型的表示范围)

erictb 2005-05-04 07:43:31
下面这个程序:
在我这里,
#include "stdafx.h"
#include <limits>
#include <iostream>
using namespace std;
这样不行

要把#include "stdafx.h"这句注释掉,才行,否则提示错误。

但我现在要在mfc中使用
numeric_limits<long double>::min() numeric_limits<long double>::max()

但在mfc中基本每个文件都包含有
#include "stdafx.h"

所以一旦用到上面两个语句就出错,我发现不是precompiled的问题,感觉是什么冲突了~
不知道大家是怎么解决这个问题的。

或者说 :如何求一个 数据类型所表示的范围??

#include "stdafx.h"
#include <limits>
#include <iostream>
using namespace std;

int main(int argc, char* argv[])
{
cout << "the size of char : " << sizeof(char) << endl
<< "the size of int : " << sizeof(int) << endl
<< "the size of double : " << sizeof(double) << endl
// << "the size of void : " << sizeof(void) << endl
// sizeof(void) --> warning #70: incomplete type is not allowed
// but the system print result, the size of void is 0
<< "the size of unsigned char : " << sizeof(unsigned char) << endl
<< "the size of signed char : " << sizeof(signed char) << endl
<< "the size of unsigned int : " << sizeof(unsigned int) << endl
<< "the size of signed int : " << sizeof(signed int) << endl
<< "the size of short int : " << sizeof(short int) << endl
<< "the size of long int : " << sizeof(long int) << endl
<< "the size of float : " << sizeof(float) << endl
<< "the size of long double : " << sizeof(long double) << endl
<< "the size of bool : " << sizeof(bool) << endl;

cout << "the size of char * : " << sizeof(char *) << endl
<< "the size of int * : " << sizeof(int *) << endl
<< "the size of double * : " << sizeof(double *) << endl
<< "the size of void * : " << sizeof(void *) << endl
<< "the size of bool * : " << sizeof(bool *) << endl;

cout << "smallest char == " << (int)numeric_limits<char>::min() << endl
<< "largest char == " << (int)numeric_limits<char>::max() << endl
<< "is the char singed ? " << numeric_limits<char>::is_signed << endl
<< "smallest int == " << numeric_limits<int>::min() << endl
<< "largest int == " << numeric_limits<int>::max() << endl
<< "smallest double == " << numeric_limits<double>::min() << endl
<< "largest double == " << numeric_limits<double>::max() << endl
<< "smallest bool == " << numeric_limits<bool>::min() << endl
<< "largest bool == " << numeric_limits<bool>::max() << endl
<< "smallest short == " << numeric_limits<short>::min() << endl
<< "largest short == " << numeric_limits<short>::max() << endl
<< "smallest long == " << numeric_limits<long>::min() << endl
<< "largest long == " << numeric_limits<long>::max() << endl
<< "smallest float == " << numeric_limits<float>::min() << endl
<< "largest float == " << numeric_limits<float>::max() << endl
<< "smallest long double == " << numeric_limits<long double>::min() << endl
<< "largest long double == " << numeric_limits<long double>::max() << endl;

cout << "smallest unsigned char == " << (unsigned int)numeric_limits<unsigned char>::min() << endl
<< "largest unsigned char == " << (unsigned int)numeric_limits<unsigned char>::max() << endl
<< "smallest unsigned int == " << numeric_limits<unsigned int>::min() << endl
<< "largest unsigned int == " << numeric_limits<unsigned int>::max() << endl
<< "smallest unsigned short == " << numeric_limits<unsigned short>::min() << endl
<< "largest unsigned short == " << numeric_limits<unsigned short>::max() << endl
<< "smallest unsigned long == " << numeric_limits<unsigned long>::min() << endl
<< "largest unsigned long == " << numeric_limits<unsigned long>::max() << endl;

return 0;
}
...全文
355 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
erictb 2005-05-04
  • 打赏
  • 举报
回复
嘿嘿,高手啊~

怎么个会引起冲突了呢~?
masterz 2005-05-04
  • 打赏
  • 举报
回复
和mfc没有关系,与 min/max 宏冲突了,用括号可以解决这个问题
cout<< "smallest long double == " << (numeric_limits<long double>::min)() << endl
<< "largest long double == " << (numeric_limits<long double>::max)() << endl;

16,551

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Creator Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

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