/*
任务的最低要求:去除注释,如果注释单独占一行,保留空行;
任务的较高要求:当注释单独占一行时,去除注释后,空行将不再保留。注释单独占一行,即本行
在分号之前,除了空格与Tab(即’\t’)外,不出现其他任何符号。
*/
/* (程序头部注释开始)
* 程序的版权和版本声明部分
* Copyright (c) 2011, 烟台大学计算机学院学生
* All rights reserved.
* 文件名称: fstream.cpp
* 作 者: 苗向前
* 完成日期: 2012 年 6 月 10 日
* 版 本 号: V 1.0
* 程序头部的注释结束
*/
#include <fstream>
#include <iostream>
using namespace std;
int main()
{
ifstream infile("WolfSheep.nls", ios::in);
ofstream outfile("WS_nocomment.nls",ios::out);
char ch[100];
int i = 0;
bool pass;
while ( !infile.eof() )
{
i = 0;
pass = false;
infile.getline(ch, 100, '\n');
while (ch[i] == '\t' || ch[i] == ' ' || ch[i] == ';')//进行简单的判断
{
if (ch[i] == ';')
{
pass = true;
break;
}
i++;
}
if (pass)
continue;
i = 0;
while (ch[i] != '\0' && ch[i] != ';')
outfile.put(ch[i++]);
outfile.put('\n');
}
infile.close();
outfile.close();
cout << "文件已去注释!" << endl;
system("PAUSE");
return 0;
}
/*
要对字符串数据进行处理首先要先得到要处理的字符串。
得到此字符串还要能够得到具体的那个位置上的字符。、、、
其实回车键就是一个字符'\n'
但是在记事本中用的是'\r\n'
大家可以尝试:
在一个空记事本中写入“联通”
保存->退出->打开
看看有什么奇怪的现象发生。
*/
十六周实验报告(四)
最新推荐文章于 2024-04-16 18:13:57 发布