• <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>
    • 軟件測試技術
    • 軟件測試博客
    • 軟件測試視頻
    • 開源軟件測試技術
    • 軟件測試論壇
    • 軟件測試沙龍
    • 軟件測試資料下載
    • 軟件測試雜志
    • 軟件測試人才招聘
      暫時沒有公告

    字號: | 推薦給好友 上一篇 | 下一篇

    Visual Studio 2010中C++的四大變化(1)

    發布: 2010-3-26 10:58 | 作者: 不詳 | 來源: 領測軟件測試網采編 | 查看: 41次 | 進入軟件測試論壇討論

    領測軟件測試網

    這段代碼循環遍歷輸出vector中的每一個數,并判斷這個數是奇數還是偶數。我們可以隨時修改Lambda表達式而改變這個匿名函數的實現,修改對集合的操作。在這段代碼中,C++使用一對中括號“[]”來表示Lambda表達式的開始,其后的”(int n)”表示Lambda表達式的參數。這些參數將在Lambda表達式中使用到。為了體會Lambda表達式的簡潔,我們來看看同樣的功能,如何使用函數對象實現:

    1. #include "stdafx.h"   
    2. #include <algorithm>   
    3. #include <iostream>   
    4. #include <ostream>   
    5. #include <vector>   
    6. using namespace std;   
    7.  
    8. struct LambdaFunctor {   
    9. void operator()(int n) const {   
    10. cout << n << " ";   
    11. if (n % 2 == 0) {   
    12. cout << " even ";   
    13. } else {   
    14. cout << " odd ";   
    15. }   
    16.  
    17. }   
    18. };   
    19.  
    20. int _tmain(int argc, _TCHAR* argv[])   
    21. {   
    22. vector<int> v;   
    23.  
    24. for (int i = 0; i < 10; ++i) {   
    25. v.push_back(i);   
    26. }   
    27.  
    28. for_each(v.begin(), v.end(), LambdaFunctor());   
    29. cout << endl;   
    30.  
    31. return 0;   
    32. }  
    33. #include "stdafx.h"  
    34. #include <algorithm> 
    35. #include <iostream> 
    36. #include <ostream> 
    37. #include <vector> 
    38. using namespace std;  
    39.  
    40. struct LambdaFunctor {  
    41. void operator()(int n) const {  
    42. cout << n << " ";  
    43. if (n % 2 == 0) {  
    44. cout << " even ";  
    45. } else {  
    46. cout << " odd ";  
    47. }  
    48.  
    49. }  
    50. };  
    51.  
    52. int _tmain(int argc, _TCHAR* argv[])  
    53. {  
    54. vector<int> v;  
    55.  
    56. for (int i = 0; i < 10; ++i) {  
    57. v.push_back(i);  
    58. }  
    59.  
    60. for_each(v.begin(), v.end(), LambdaFunctor());  
    61. cout << endl;  
    62.  
    63. return 0;  
    64. }  

    延伸閱讀

    文章來源于領測軟件測試網 http://www.kjueaiud.com/

    22/2<12

    關于領測軟件測試網 | 領測軟件測試網合作伙伴 | 廣告服務 | 投稿指南 | 聯系我們 | 網站地圖 | 友情鏈接
    版權所有(C) 2003-2010 TestAge(領測軟件測試網)|領測國際科技(北京)有限公司|軟件測試工程師培訓網 All Rights Reserved
    北京市海淀區中關村南大街9號北京理工科技大廈1402室 京ICP備10010545號-5
    技術支持和業務聯系:info@testage.com.cn 電話:010-51297073

    軟件測試 | 領測國際ISTQBISTQB官網TMMiTMMi認證國際軟件測試工程師認證領測軟件測試網

    老湿亚洲永久精品ww47香蕉图片_日韩欧美中文字幕北美法律_国产AV永久无码天堂影院_久久婷婷综合色丁香五月

  • <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>