我正在编写一个 C++ 程序来显示文本文件中引号或单行或多行注释中的任何文本。问题是我不能让它正常运行。这是我的程序:
#include <iostream.h>
#include <fstream.h>
#include <string.h>
#include<conio.h>
using namespace std;
int main () {
char ch, name[20];
int count=0;
fstream fin;
cin>>name;
fin.open(file_name, ios::in);
while(!fin.eof()) {
fin.get(ch);
if(ch=='/') {
fin.get(ch);
if(ch=='*') {
a:
fin.get(ch);
while(ch!='*') {
cout<<ch;
fin.get(ch);
}
fin.get(ch);
if(ch!='/') goto a;
}
if(ch=='/') {
fin.get(ch);
while(ch!='\n') {
cout<<ch;
fin.get(ch);
}
}
}
}
getch();
return 0;
}
编辑:它陷入无限循环。我知道如何。问题仍然存在。我正在使用 Dev C++ 编辑器。