这是我写的代码,编译没问题,不知为何控制台空白一片,求指点!
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
fstream file;
file.open("menu.cpp",ios::out);
if (!file)
{
cout<<"no file to be found!\n";
return -1;
}
char ch,ch1;
while(file.get(ch))
{
if (ch=='/') // 当读到第一个“/”
{
file.get(ch1);
if (ch1=='/') // 当读到第二个“/”
{
while(file.get(ch)) // 继续往下读
{
if (ch=='\n')
{
cout<<endl;
break;
}
}
}
else // 没读到第二个“/”
{
cout<<ch;
cout<<ch1;
}
}
else if(ch=='\n') // 当文件中读到换行符时
{
cout<<endl;
}
else // 读到一般内容
{
cout.put(ch);
}
}
file.close();
return 0;
}