Skip to content

Instantly share code, notes, and snippets.

@LizardLeliel
Created October 14, 2014 17:48
Show Gist options
  • Save LizardLeliel/5e612e02f4c9ae67a5bf to your computer and use it in GitHub Desktop.
Save LizardLeliel/5e612e02f4c9ae67a5bf to your computer and use it in GitHub Desktop.
A program that outputs its source code. The logic in this file is my own design; I didn't strictly follow code conventions for this exercise, hence the function named function.
#include <iostream>
#include <string>
using namespace std;
void function(string var, int flag);
int main(){
function(R"!(
#include <iostream>
#include <string>
using namespace std;
void function(string var, int flag);
int main(){)!", 1);
function(R"!(
return 0;
}
void function(string var, int flag){
const string startFunction = R"#(
function(R"!()#";
const string midFunction = { ')', '!', '"', ',', ' ', '\0' };
const string endFunction = R"#();)#";
if (flag == 1) {
cout << var;
cout << startFunction << var << midFunction << flag << endFunction;
}
else {
cout << startFunction << var << midFunction << flag << endFunction;
cout << var;
}
}
)!", 0);
return 0;
}
void function(string var, int flag){
const string startFunction = R"#(
function(R"!()#";
const string midFunction = { ')', '!', '"', ',', ' ', '\0' };
const string endFunction = R"#();)#";
if (flag == 1) {
cout << var;
cout << startFunction << var << midFunction << flag << endFunction;
}
else {
cout << startFunction << var << midFunction << flag << endFunction;
cout << var;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment