十六周任务四将分号后的文字去掉

/* (程序头部注释开始)
* 程序的版权和版本声明部分
* Copyright (c) 2011, 烟台大学计算机学院学生 
* All rights reserved.
* 文件名称:    十六周任务四                          
* 作    者:     石丽君                         
* 完成日期:       2012  年    6   月     5   日
* 版 本 号:          

* 对任务及求解方法的描述部分
* 输入描述:
要求编写C++程序,读WolfSheep.nls,去除其中所有的注释,并保存到文件WS_nocomment.nls 中。
例如,WolfSheep.nls 中下面的一段代码:
ask patches [ set pcolor green ]
; check GRASS? switch.
; if it is true, then grass grows and the sheep eat it. if it false, then the sheep don't need to eat
if grass? [
ask patches [
set countdown random grass‐regrowth‐time ; initialize grass grow clocks randomly
set pcolor one‐of [green brown]
]
]
经过处理后,在WS_nocomment.nls 中,上面划线部分的注释将全部不存在。
提示1:任务的另一种直白的解读是:读入每一行,复制每一行分号前面的部分。或者说,读入每
一行,逐个复制文件中的字符,如果出现分号,分号及其后的文字将不再复制。
* 问题描述: 
* 程序输出: 
* 程序头部的注释结束
*/


#include<iostream>
#include<fstream>
using namespace std;
int main()
{
	ifstream readFile;
	ofstream writeFile;
	char ch[200];int n;
	readFile.open("WolfSheep.nls",ios::in);
	writeFile.open("WS_nocomment.nls",ios::out);
	while(!readFile.eof())
	{
		readFile.getline(ch,200,'\n');
		n=strlen(ch);
		for(int i=0;i<n;i++)
		{
			if(ch[i]!=';')
				writeFile<<ch[i];
			else
				break;
		}
	
	writeFile<<'\n';
	}
	readFile.close();
	writeFile.close();
	cout<<"finish!"<<endl;
	system("pause");
	return 0;


}



评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值