利用C++删除智能合约(Solidity)的注释

注意问题:
1.智能合约注释有三种 //, //, *
2.保存文件要加上你想要变成文件的后缀,eg: “.txt”

#include"pch.h"
#include <fstream>  
#include <iostream>
using namespace std;
void trans(const char *,const  char *);
int main()
{
	trans("f:\\delete_note.txt", "f:\\delete_note_1.txt");
	system("pause");
}
void trans(const char *icpp,const char *ocpp)
{
	fstream incpp(icpp, ios::in); //读文件
	fstream outcpp(ocpp, ios::out);//写文件
	char c, flag = '\0';
	while (incpp.get(c))
	{
		if (c == '-')
		{
			incpp.get(c);
			if (c == '-')
			{
				while (c != '\n')//如果没有指到转行符,就一直读取
					incpp.get(c);
				incpp.get(c);//删除空行
			}
		}
		if (c == '*')
		{
			while (c != '\n')//如果没有指到转行符,就一直读取
				incpp.get(c);
			incpp.get(c);//删除空行
		}

		if (c == '/')
		{
			incpp.get(c); //读取当前字符,指向下个字符
			if (c != '/'&&c != '*')
				outcpp << "/" << c;		//如果下一个字符不是‘/’或‘*’,则为一般除号,正常输出
			else
			{
				if (c == '/')
				{
					while (c != '\n')//如果没有指到转行符,就一直读取
						incpp.get(c);
				}
				else   //c=='*'的情况
				{
					while (flag != '/')
					{
						flag = '\0';
						incpp.get(c);
						if (c == '*')
							incpp.get(flag);	//判别/*…*/注释是否结束
					}
					incpp.get(c);				//去掉多余空格
				}
			}
		}
		else
			outcpp << c;
	}
	incpp.close();
	outcpp.close();
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值