Last active
September 13, 2017 19:11
-
-
Save kadirmalak/2df5394617848ec16c570675db3305e3 to your computer and use it in GitHub Desktop.
Self Reproducing Program (Quine) in C++
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
#include <vector> | |
using namespace std; | |
int main() | |
{ | |
auto source = vector<string>{ | |
"#include <iostream>", | |
"#include <string>", | |
"#include <vector>", | |
"", | |
"using namespace std;", | |
"", | |
"int main()", | |
"{", | |
" auto source = vector<string>{", | |
" {SRC}", | |
" };", | |
"", | |
" for (auto line : source)", | |
" {", | |
" if (line == \" {SRC}\")", | |
" {", | |
" for (auto line2 : source)", | |
" {", | |
" cout << \" \" << '\"';", | |
" for (auto ch : line2)", | |
" {", | |
" if (ch == '\\\\' || ch == '\"') {", | |
" cout << '\\\\';", | |
" }", | |
" cout << ch;", | |
" }", | |
" cout << '\"' << \",\" << endl;", | |
" }", | |
" }", | |
" else {", | |
" cout << line << endl;", | |
" }", | |
" }", | |
"", | |
" return 0;", | |
"}", | |
"", | |
}; | |
for (auto line : source) | |
{ | |
if (line == " {SRC}") | |
{ | |
for (auto line2 : source) | |
{ | |
cout << " " << '"'; | |
for (auto ch : line2) | |
{ | |
if (ch == '\\' || ch == '"') { | |
cout << '\\'; | |
} | |
cout << ch; | |
} | |
cout << '"' << "," << endl; | |
} | |
} | |
else { | |
cout << line << endl; | |
} | |
} | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment