* 輸入描述:文件WolfSheep.nls
* 問題描述:要求編寫C++程序,讀WolfSheep.nls,去除其中所有的註釋,並保存到文件WS_nocomment.nls 中
讀入每一行,複製每一行分號前面的部分。或者說,讀入每一行,逐個複製文件中的字符,
如果出現分號,分號及其後的文字將不再複製。
去除註釋,如果註釋單獨佔一行,保留空行;
* 程序輸出:WS_nocomment.nls
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
int i,m;
ifstream readFile;
ofstream writeFile;
char ch[200];
readFile.open("WolfSheep.nls", ios::in);
writeFile.open("WS_nocomment.nls", ios::out);
while (!readFile.eof())
{
readFile.getline(ch,200,'\n');
m=strlen(ch);
for(i=0;i<m;++i)
{
if(ch[i]!=';')
{
writeFile<<ch[i];
}
else
{
break;
}
}
writeFile<<'\n';
}
readFile.close();
writeFile.close();
cout << "Finish!" << endl;
system("pause");
return 0;
}