| 以下为引用的内容: 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(); } |
| 以下为引用的内容: /* (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(); } |
| 以下为引用的内容: while(getline(infile, line)) lines[line_num++] = line; |
| 以下为引用的内容: for_each(lines.begin(), lines.end(), print_map()); |
| 以下为引用的内容: struct print_map { void operator() (pair<int, string> p) { cout << p.first << " " << p.second << endl; outfile << p.first << " " << p.second << endl; } }; |