一个滤掉C/C++风格的注释的片段
/* * A simple code to filter the C/C++ source code. * Copyright (c) 2007 freebsd13 <freebsd13@163.com> */ #include <iostream> using namespace std; int main() { char ch,ch1= 0; while(cin.get(ch)) { if(ch == '/') { cin.get(ch); switch(ch) { case '/': do{ cin.get(ch); }while(ch!='\n'); cout<<ch; break; case '*': do{ cin.get(ch); cin.get(ch1); cin.putback(ch1); }while(!(ch == '*'&&ch1 == '/')); cin.get(ch);//吃掉放回去的字符 break; default: cout<<'/'; cout<<ch; } }else cout<<ch; } return 0; }