注意问题:
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();
}
6709

被折叠的 条评论
为什么被折叠?



