list11-1.cpp

来自「这是关于VC++中的STL容器的资料,包括了STL容器各个类之间关系以及类的说明」· C++ 代码 · 共 50 行

CPP
50
字号

// Listing 11.1
// This program uses numeric_limits::epsilon(), and
// numeric_limits::max() To build a test case vector.

#include <stdlib.h>
#include <iostream>
#include <limits>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <iomanip>

using namespace std;

void main(void)
{

    int N;
    vector<float> TestSet;
    vector<float>::iterator I;
    string R;
    numeric_limits<float> Real;
    stringstream Stream;
    srand(Real.epsilon());
    TestSet.push_back(Real.max());
    TestSet.push_back(Real.epsilon());
    for(N = 0;N < 40;N++)
    {

       TestSet.push_back(rand() * 0.10);
    }
    random_shuffle(TestSet.begin(),TestSet.end());
    I = TestSet.begin();
    cout.precision(10);
    cout.setf(ios::showpoint | ios::fixed);
    Stream << setiosflags(ios::showpoint | ios::fixed) <<  Real.max() << ends;
    Stream >> R;
    while(I != TestSet.end())
    {
       cout << setw(R.length()) << *I << endl;
       I++;
    }



}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?