当前位置:首页 > 网络编程 > WEB编程 > ASP.net > .net开发:如何为程式码加上行号

.net开发:如何为程式码加上行号

点击次数:29 次 发布日期:2008-11-21 22:06:31 作者:源代码网
源代码网推荐

源代码网整理以下Abstract

源代码网整理以下若需要将程式码放进word交报告或做文件时,或许我们会想将程式码加上行号方便讲解,如同博客园显示程式码那样,我们该如何做呢?

源代码网整理以下Introduction

源代码网整理以下使用环境:Visual C++ 9.0 / Visual Studio 2008

源代码网整理以下一段C++的小程式,可以帮程式码加上行号后输出。 
  

以下为引用的内容:

源代码网整理以下      map_code_line.cpp / C++
         /*
         (C) OOMusou 2008 http://oomusou.cnblogs.com

源代码网整理以下         Filename    : map_code_line.cpp
         Compiler    : Visual C++ 9.0 / Visual Studio 2008
         Description : Demo how to add line number for code
         Release     : 07/18/2008 1.0
         */
         #include <iostream>
         #include <fstream>
         #include <string>
         #include <map>
         #include <algorithm>
         using namespace std;
         ifstream infile("map_code_line.cpp");
         ofstream outfile("map_code_line_r.cpp");
         struct print_map {
           void operator() (pair<int, string> p) {
             cout    << p.first << " " << p.second << endl;
             outfile << p.first << " " << p.second << endl;
           }
         };
         int main() {
           map<int, string> lines;
           string line;
           int line_num = 1;
           while(getline(infile, line))
           lines[line_num++] = line;
           infile.close();
           for_each(lines.begin(), lines.end(), print_map());
           outfile.close();
         }

 
执行结果

源代码网整理以下 源代码网供稿.

网友评论 (0)
会员中心
网络编程
本站推荐
网络编程之精华