Im an IT student(just started)
we had this basic assignment:
Antivirus
Suppose you are going to create an antivirus program. You will need to search a file for any trace of a virus and if found it should be removed. However, a backup of the original(“infected file”) file should be kept prior to removal of the virus.
Given the text file "Virus.txt", search for any instance of the word "virus" remove it then make a new copy of the file. Remember to back up the original file.
For example, you are given the following text file:
@#$5gert#$%#&^&%^&%^&%&%&%^&%^&
VIRUS
Jklljkljljmbmbnmfghfhfg
VIRUS
hkjwqwqczxczbmnbjklhgjlfdf
VIRUS
Nmfghfh
VIRUS
fghkjwqwqczxczxc
VIRUS
bmnbjklhgjlfdf
312312312
VIRUS
3';jkl';l;ljk8-=53453-3=087788232
VIRUS
3fhhf7862!@4567dfsbnhfgjt
The output would be:
@#$5gert#$%#&^&%^&%^&%&%&%^&%^&
Jklljkljljmbmbnmfghfhfg
hkjwqwqczxczbmnbjklhgjlfdf
Nmfghfh
fghkjwqwqczxczxc
bmnbjklhgjlfdf
312312312
3';jkl';l;ljk8-=53453-3=087788232
3fhhf7862!@4567dfsbnhfgjt
Scan complete...
7 threats have been detected and removed."
Note: You should write your output both on the screen and to a text file.
and this is the code I made:
(uhhhh...so incomplete...)
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <string>
using namespace std;
void deleting(ifstream& Nstream, ofstream& Ostream);
int main()
{
ifstream instream;
ofstream outstream;
ofstream backup;
backup.open("backup.txt", ios::out);
instream.open("Virus.txt");
char N;
while(!instream.eof())
{
instream.get(N);
backup << N;
}
backup.close();
outstream.open("novirus.txt", ios::out|ios::in);
deleting(instream, outstream);
instream.close();
outstream.close();
cout << "Scan somplete...\n";
system ("pause");
return 0;
}
void deleting(ifstream& Nstream, ofstream& Ostream)
{
while (!Nstream.eof())
{
char X;
Nstream.get(X);
if
((X == 'V') || (X == 'I') || (X == 'R') || (X == 'U') || (X == 'S'))
Ostream << "";
else
Ostream << X;
/*Nstream.get(X);*/
}
}
what I would like to know is how come the void function doesn't work unless I delete the:
~ofstream backup;
backup.open("backup.txt", ios::out);
instream.open("Virus.txt");
char N;
while(!instream.eof())
{
instream.get(N);
backup << N;
}
backup.close();~
?????...how can i open three text files??
please help