中文字幕 另类精品,亚洲欧美一区二区蜜桃,日本在线精品视频免费,孩交精品乱子片免费

<sup id="3hn2b"></sup>

    1. <sub id="3hn2b"><ol id="3hn2b"></ol></sub><legend id="3hn2b"></legend>

      1. <xmp id="3hn2b"></xmp>

      2. 新聞中心

        EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應(yīng)用 > 如何為程序代碼加上行號

        如何為程序代碼加上行號

        作者: 時間:2011-05-12 來源:網(wǎng)絡(luò) 收藏

        若需要將放進(jìn)詞交報告或做文件時,或許我們會想將方便講解,如同博客園顯示那樣,我們該做呢?

        本文引用地址:http://www.antipu.com.cn/article/150758.htm

        介紹
        使用環(huán)境:Visual C++ 9.0/視覺演播室2008年

        一段C++的小程序,可以幫程序代碼后輸出。

        map_code_line.cpp/C++


        1/*
        2 (c) OOMusou 2008年
        3
        4文件名 : map_code_line.cpp
        5編譯器 : Visual C++ 9.0/視覺演播室2008年
        6描述: 演示增加代碼的
        7發(fā)行 : 07/18/2008 1.0
        8 *
        9 #include iostream>
        10 #include fstream>
        11 #include string>
        12 #include map>
        13 #include algorithm>
        14
        15使用namespace std;
        16
        17 infile的ifstream (“map_code_line.cpp”);
        18 outfile的ofstream (“map_code_line_r.cpp”);
        19
        20 struct print_map {
        21空操作員() (pairint, string> p) {
        22 cout p.first ““ p.second endl;
        23 outfile p.first ““ p.second endl;
        24}
        25};
        26
        27 int扼要() {
        28 mapint, string>線;
        29
        30串線;
        31 int line_num = 1;
        32,當(dāng)時(infile的getline (線))
        33 線[line_num++] =線;
        34
        35 infile.close ();
        36
        37 for_each (lines.begin (), lines.end (), print_map ());
        38 outfile.close ();
        39}

        執(zhí)行結(jié)果

        1/*
        2 (c) OOMusou 2008年
        3
        4文件名 : map_code_line.cpp
        5編譯器 : Visual C++ 9.0/視覺演播室2008年
        6描述: 演示增加代碼的行號
        7發(fā)行 : 07/18/2008 1.0
        8 *
        9 #include iostream>
        10 #include fstream>
        11 #include string>
        12 #include map>
        13 #include algorithm>
        14
        15使用namespace std;
        16
        17 infile的ifstream (“map_code_line.cpp”);
        18 outfile的ofstream (“map_code_line_r.cpp”);
        19
        20 struct print_map {
        21 空操作員() (pairint, string> p) {
        22 cout p.first ““ p.second endl;
        23 outfile p.first ““ p.second endl;
        24 }
        25};
        26
        27 int扼要() {
        28 mapint, string>線;
        29
        30 串線;
        31 int line_num = 1;
        32 當(dāng)時(infile的getline (線))
        33 線[line_num++] =線;
        34
        35 infile.close ();
        36
        37 for_each (lines.begin (), lines.end (), print_map ());
        38 outfile.close ();
        39}


        32行


        當(dāng)時(infile的getline (線))
        線[line_num++] =線;

        是整個程序的關(guān)鍵:使用地圖,關(guān)鍵存放行號,價值存放每一行的程序代碼。而且隨著每一行程序代碼的讀入,自動增加行號。

        37行


        for_each (lines.begin (), lines.end (), print_map ());

        將地圖內(nèi)容印出,因為地圖無法配合拷貝(),只好退而求其次使用for_each ()與functor。

        20行


        struct print_map {
        空操作員() (pairint, string> p) {
        cout p.first ““ p.second endl;
        outfile p.first ““ p.second endl;
        }
        };

        配合for_each ()的functor, 22行的cout可以拿掉,只是方面在屏幕顯示而已。

        結(jié)論
        STL的地圖是很好用的容器,尤其子鏈寫法,若索引下沒有元素,會自動新增,所以才會有排行[line_number++] =線; 這么漂亮的寫法。



        關(guān)鍵詞: 行號 加上 代碼 程序 如何

        評論


        相關(guān)推薦

        技術(shù)專區(qū)

        關(guān)閉