可以試試正則表示式,功能很強大,自己寫一個的話,可參考:
#include
usingnamespacestd;
voiddeleteComments(char*,int);
intmain(){
stringfilename;
cout
cin>>filename;
ifstreamfin;
try{
fin.open(filename.c_str());
}catch(std::exception&e)
{
}
if(fin.is_open())
charbuf[102400];
intn=fin.readsome(buf,sizeof(buf));//read(buf,sizeof(buf));
if(n==-1)
fin.close();
deleteComments(buf,n);
return0;
voiddeleteComments(char*buf,intn)
char*p,*end,c;
p=buf;
end=buf+n;
char*pos1=NULL,*pos2=NULL;
boolflag1=false,flag2=false;//"and"
intflag3=0,flag4=0,flag5=0;//for/*...//...*/
while(p
可以試試正則表示式,功能很強大,自己寫一個的話,可參考:
#include
#include
usingnamespacestd;
voiddeleteComments(char*,int);
intmain(){
stringfilename;
cout
cin>>filename;
ifstreamfin;
try{
fin.open(filename.c_str());
}catch(std::exception&e)
{
cout
}
if(fin.is_open())
{
cout
}
charbuf[102400];
intn=fin.readsome(buf,sizeof(buf));//read(buf,sizeof(buf));
if(n==-1)
{
fin.close();
}
deleteComments(buf,n);
cout
return0;
}
voiddeleteComments(char*buf,intn)
{
char*p,*end,c;
p=buf;
end=buf+n;
char*pos1=NULL,*pos2=NULL;
boolflag1=false,flag2=false;//"and"
intflag3=0,flag4=0,flag5=0;//for/*...//...*/
while(p