Aug 9, 2013 at 5:38pm UTC
I read about quines on Wikipedia and thought they were kind of interesting. I made a program and I wanted to know if it is considered a quine.
#include <fstream>
#include <windows.h>
using namespace std;
int main()
{
system("@echo off");
ofstream a_file("example.cpp");
a_file << "#include <fstream>\n";
a_file << "#include <windows.h>\n";
a_file << "using namespace std;\n";
a_file << "int main()\n";
a_file << "{\n";
a_file << "\tsystem(\"@echo off\");\n";
a_file << "\tofstream a_file(\"example2.cpp\");\n";
a_file << "\ta_file << \"#include <fstream>\\n\";\n";
a_file << "\ta_file << \"#include <windows.h>\\n\";\n";
a_file << "\ta_file << \"using namespace std;\\n\";\n";
a_file << "\ta_file << \"int main()\\n\";\n";
a_file << "\ta_file << \"{\\n\";\n";
a_file << "\ta_file << \"\tsystem(\\\"@echo off\\\");\\n\";\n";
a_file << "\ta_file << \"\tofstream a_file(\\\"example2.cpp\\\");\\n\";\n";
a_file << "\ta_file << \"\tsystem(\\\"pause\\\");\\n\";\n";
a_file << "\ta_file << \"\treturn 0;\\n\";\n";
a_file << "\ta_file << \"}\";\n";
a_file << "\tsystem(\"pause\");\n";
a_file << "\treturn 0;\n";
a_file << "}";
system("pause");
return 0;
}
>>>>>>>>>>>>>>> example.cpp <<<<<<<<<<<<<<<
#include <fstream>
#include <windows.h>
using namespace std;
int main()
{
system("@echo off");
ofstream a_file("example2.cpp");
a_file << "#include <fstream>\n";
a_file << "#include <windows.h>\n";
a_file << "using namespace std;\n";
a_file << "int main()\n";
a_file << "{\n";
a_file << " system(\"@echo off\");\n";
a_file << " ofstream a_file(\"example2.cpp\");\n";
a_file << " system(\"pause\");\n";
a_file << " return 0;\n";
a_file << "}";
system("pause");
return 0;
}
>>>>>>>>>>>>>>> example2.cpp <<<<<<<<<<<<<<<
#include <fstream>
#include <windows.h>
using namespace std;
int main()
{
system("@echo off");
ofstream a_file("example2.cpp");
system("pause");
return 0;
}
Also, since quines print the source code of the program, how do viruses replicate themselves if they are already compiled?
Aug 9, 2013 at 6:02pm UTC
I'm not entirely sure what you're asking, finding out if a program is a quine is just a matter of running it and checking :P
Last edited on Aug 9, 2013 at 6:02pm UTC
Aug 9, 2013 at 6:17pm UTC
why not just have it open itsself and read every file of the line?
Aug 9, 2013 at 10:00pm UTC
I made a program and I wanted to know if it is considered a quine.
No. The source you're writing out is not the same as the original source.
how do viruses replicate themselves if they are already compiled?
Viruses replicate at the machine code level; they add new code to the host program and modify the existing code to reroute calls to their own proceedures.
Andy
Last edited on Aug 9, 2013 at 10:08pm UTC