numeric_limits::min() (如何求一个类型的表示范围)
下面这个程序:
在我这里,
#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;
}