📄 2ex1.cpp
字号:
//第2章 习题1
#include <fstream.h>
#include <iostream.h>
#include <conio.h>
void pro_process(char *);
void main()
{
char buf[4048]={'\0'};//扫描缓冲区
//调用预处理程序
pro_process(buf);
//屏幕显示
cout<<buf<<endl;
}
void pro_process(char *buf)
{
ifstream cinf("source.txt",ios::in);
int i=0;char c;//计数器,当前字符。
bool in_comment=false;//状态标志,false表示当前字符未处于注释中。
while(cinf.read(&c,sizeof(char))){//从文件读一个字符
switch(in_comment){
case false:
if(c=='{' )//进入注释
in_comment=true;
else
buf[i++]=c=='\t'||c==0x0a?' ':c ;
break;
case true:
if(c=='}' )//离开注释
in_comment=false;
}//end of switch
}//end of while
buf[i]='#';
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -