首页 > 代码库 > 小程序-去除单行注释
小程序-去除单行注释
数据结构的文档一行代码要附上两三行注释呢……比如这样:
T& back(); // return the element at the rear of the vector. // Precondition: the vector is not empty. if vector // is empty, throws the underflowError exception
讲道理作为注释它有帮助的……不过读起来不方便,在清楚函数的含义的时候可以考虑清除它们。
小程序功能有限,将源代码复制到sorce.txt,会生成一个new.txt。
或许有一天会回来扩展呢:
图形化界面,打开任意文件,输出到剪贴板等。
#include <iostream>#include <fstream>#include <string>using namespace std;const char* filePath = "sorce.txt"; //本注释会被删除 bool isNote(const string &); //本注释不会被删除 int main(){ ifstream infile(filePath, ios::in); if(!infile){ cout << "转换失败,请将文件重命名为 sorce.txt" <<endl; } else{ ofstream outfile("new.txt", ios::out); string line; while(!infile.eof()){ getline(infile, line); if(!isNote(line)){ //这一行是注释行吗? outfile << line << endl; } } outfile.close(); cout << "转换成功!" << endl; } infile.close(); return 0;}bool isNote(const string & s){ for(int i = 0; i < s.size(); i++){ if(s[i] != ‘ ‘){ if(s[i] == ‘/‘){ return true; } else{ return false; } } } return false;}
小程序-去除单行注释
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。