乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      流和STL迭代器

       孤步 2012-07-24

      在vc++中程序中用了srandom()和random(),頭文件為stdlib.h,但編譯出現(xiàn)錯誤error C3861: “srandom”: 找不到標(biāo)識符。
        原因是現(xiàn)在vc++編譯器的庫函數(shù)中沒有randomize()和random(),分別用srand()和rand()代替了。
        #include <time.h> //定義關(guān)于時間的函數(shù)  
        一般在用到time(NULL)(當(dāng)前時間)函數(shù)時需要包含此頭文件  
        #include <stdlib.h> //定義雜項函數(shù)及內(nèi)存分配函數(shù)  
        一般在用到rand()和srand()函數(shù)時需要包含此頭文件  

        函數(shù)名: random 功 能: 隨機(jī)數(shù)發(fā)生器,也就是產(chǎn)生一個隨機(jī)數(shù)  
        用 法: int random(int num);  
        產(chǎn)生的隨機(jī)數(shù)范圍為0~num-1。  

        函數(shù)名: randomize  
        功 能: 初始化隨機(jī)數(shù)發(fā)生器,相當(dāng)于撥隨機(jī)種子  
        用 法: void randomize(void);


      /************************************************************************/

      /*

      對于迭代器,有另一種方法使用流和標(biāo)準(zhǔn)函數(shù)。理解的要點是將輸入/輸出流作為容器看待。

      因此,任何接受迭代器參數(shù)的算法都可以和流一起工作。

       

        函數(shù)Display()顯示了如何使用一個輸出流迭代器。下面的語句將容器中的值傳輸?shù)?/span>cout輸出流對象中:

       

        copy(v.begin(), v.end(),

        ostream_iterator<int>(cout, "\t"));

      第三個參數(shù)實例化了ostream_iterator<int>類型,并將它作為copy()函數(shù)的輸出目標(biāo)迭代器對象?!?/span>\t”字符串是作為分隔符。

                                                                           */

      /************************************************************************/

      #include <iostream>

      #include <stdlib.h>    // Need random(), srandom()

      #include <time.h>      // Need time()

      #include <algorithm>   // Need sort(), copy()

      #include <vector>      // Need vector

       

      using namespace std;

       

      void Display(vector<int>& v, const char* s);

       

      int main()

      {

             // Seed the random number generator

             srand(time(NULL));

             // Construct vector and fill with random integer values

             vector<int> collection(10);

             for (int i = 0; i < 10; i++)

              collection[i] = rand() % 10000;

            

             // Display, sort, and redisplay

             Display(collection, "Before sorting");

             sort(collection.begin(), collection.end());

             Display(collection, "After sorting");

             return 0;

      }

       

      // Display label s and contents of integer vector v

      void Display(vector<int>& v, const char* s)

      {

             cout << endl << s << endl;

             copy(v.begin(), v.end(),ostream_iterator<int>(cout, "  "));

             cout << endl;

      }

        本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
        轉(zhuǎn)藏 分享 獻(xiàn)花(0

        0條評論

        發(fā)表

        請遵守用戶 評論公約

        類似文章 更多