...
#include <fstream>
#include <iostream>
#include <cstdlib>
#include <conio.h>
using namespace std;
void get(ifstream& in_stream, ofstream& out_stream);
int main()
{
ifstream fin;
ofstream fout;
cout << "Begin editing files.\n";
fin.open("original.txt");
if (fin.fail())
{
cout << "Input file opening failed.\n";
getch();
exit(1);
}
fout.open("correct.txt");
if (fout.fail())
{
cout << "Output file opening failed.\n";
getch();
exit(1);
}
get(fin, fout);
fin.close();
fout.close();
cout << "End of editing files.\n";
getch();
return 0;
}
void get(ifstream& in_stream, ofstream& out_stream)
{
char next;
in_stream.get(next); //get first character
while (! in_stream.eof()) //detect the end of the input file
{
if (next=='c')
{
out_stream.put(next); //ouptput c
in_stream.get(next);
if (next=='i')
{
out_stream.put(next); //ouptput i
in_stream.get(next);
if (next=='n')
{
out_stream.put(next); //ouptput n
in_stream.get(next); //get blank
out_stream.put(next); //output blank
in_stream.get(next);
if (next=='<')
{
out_stream.put('>'); //correct mistake
in_stream.get(next);
if (next=='<')
{
out_stream.put('>'); //correct mistake
in_stream.get(next);
}
}
}
}
else if (next=='o')
{
out_stream.put(next); //ouptput o
in_stream.get(next);
if (next=='u')
{
out_stream.put(next); //ouptput u
in_stream.get(next);
if (next=='t')
{
out_stream.put(next); //ouptput t
in_stream.get(next);
out_stream.put(next);
in_stream.get(next);
if (next=='>')
{
out_stream.put('<'); //correct mistake
in_stream.get(next);
if (next=='>')
{
out_stream.put('<'); //correct mistake
in_stream.get(next);
}
}
}
}
}
}
out_stream.put(next);
in_stream.get(next);
}
}
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.115.219.78