did i make a virus?

closed account (1vf9z8AR)
I wrote a program to write infinite files and hence eat up all the memory of your computer.Does it work?The program doesnt end and my antivirus doesn't do anything to close it.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
  #include<iostream>
using namespace std;
#include<fstream>
#include<string.h>
int main()
{
        ofstream w[5];int n;
        string filename[5]={"a.txt","b.txt","c.txt","d.txt","e.txt"};
        for(int i=0;i<n;i++)
        {
                for(int j=0;j<5;j++)
                {
                        w[j].open(filename[j]);
                        w[j]<<"hello";
                        w[j].close();
                }
        }

        return 0;
}

Viruses replicate themselves. Your program has undefined behaviour because it uses the uninitialized variable n. In theory this means that the program could act as a virus but that is unlikely. What you have here is probably a program that (over)writes "hello" to five files an unknown (possibly infinite) number of times.
Last edited on
closed account (1vf9z8AR)
how do i get it to replicate in a simple way?
the first arg to argc in main is the program name, probably with its full path. You can use that to make a copy of the current executable to another name in another place if your OS will allow you to copy a program that is currently running (it may or may not).
Topic archived. No new replies allowed.