E
Emlyn Corrin
I was bored, so I just wrote a quine (program that will print out it's own
source code when run) in 100% ansi c++, without using any c-library
functions (such as printf), and not making any assumptions on the character
set.
Any comments? bugs? ideas on how to shorten it?
Emlyn
#include <string>
#include <iostream>
using namespace std;
int main() {
string s = "s", s0 = "\n", s1 = "\"", s2 = "\\", s3 = "n", s4 = ";";
string s5 = " string s", s6 = ", s", s7 = " = ", s8 = s7+s1, s9 = "+";
string s10 = "#include <string>", s11 = "#include <iostream>";
string s12 = "using namespace std;", s13 = "int main() {";
string s14 = " return 0;", s15 = "}";
string s20 = " cout<<s10<<s0<<s11<<s0<<s12<<s0<<s13<<s0;";
string s21 = "
cout<<s5<<s8<<s<<s1<<s6<<0<<s8<<s2<<s3<<s1<<s6<<1<<s8<<s2<<s1<<s1<<s6;";
string s22 = "
cout<<2<<s8<<s2<<s2<<s1<<s6<<3<<s8<<s3<<s1<<s6<<4<<s8<<s4<<s1<<s4<<s0;";
string s23 = "
cout<<s5<<5<<s8<<s5<<s1<<s6<<6<<s8<<s6<<s1<<s6<<7<<s8<<s7<<s1;";
string s24 = "
cout<<s6<<8<<s7<<s<<7<<s9<<s<<1<<s6<<9<<s8<<s9<<s1<<s4<<s0;";
string s25 = " cout<<s5<<10<<s8<<s10<<s1<<s6<<11<<s8<<s11<<s1<<s4<<s0;";
string s26 = " cout<<s5<<12<<s8<<s12<<s1<<s6<<13<<s8<<s13<<s1<<s4<<s0;";
string s27 = " cout<<s5<<14<<s8<<s14<<s1<<s6<<15<<s8<<s15<<s1<<s4<<s0;";
string s28 = "
cout<<s5<<20<<s8<<s20<<s1<<s4<<s0<<s5<<21<<s8<<s21<<s1<<s4<<s0<<s5<<22<<s8<<
s22<<s1<<s4<<s0;";
string s29 = "
cout<<s5<<23<<s8<<s23<<s1<<s4<<s0<<s5<<24<<s8<<s24<<s1<<s4<<s0<<s5<<25<<s8<<
s25<<s1<<s4<<s0;";
string s30 = "
cout<<s5<<26<<s8<<s26<<s1<<s4<<s0<<s5<<27<<s8<<s27<<s1<<s4<<s0<<s5<<28<<s8<<
s28<<s1<<s4<<s0;";
string s31 = "
cout<<s5<<29<<s8<<s29<<s1<<s4<<s0<<s5<<30<<s8<<s30<<s1<<s4<<s0<<s5<<31<<s8<<
s31<<s1<<s4<<s0;";
string s32 = "
cout<<s5<<32<<s8<<s32<<s1<<s4<<s0<<s5<<33<<s8<<s33<<s1<<s4<<s0<<s5<<34<<s8<<
s34<<s1<<s4<<s0;";
string s33 = "
cout<<s5<<35<<s8<<s35<<s1<<s4<<s0<<s5<<36<<s8<<s36<<s1<<s4<<s0;";
string s34 = "
cout<<s20<<s0<<s21<<s0<<s22<<s0<<s23<<s0<<s24<<s0<<s25<<s0<<s26<<s0<<s27<<s0
<<s28<<s0;";
string s35 = "
cout<<s29<<s0<<s30<<s0<<s31<<s0<<s32<<s0<<s33<<s0<<s34<<s0<<s35<<s0<<s36<<s0
;";
string s36 = " cout<<s14<<s0<<s15<<s0;";
cout<<s10<<s0<<s11<<s0<<s12<<s0<<s13<<s0;
cout<<s5<<s8<<s<<s1<<s6<<0<<s8<<s2<<s3<<s1<<s6<<1<<s8<<s2<<s1<<s1<<s6;
cout<<2<<s8<<s2<<s2<<s1<<s6<<3<<s8<<s3<<s1<<s6<<4<<s8<<s4<<s1<<s4<<s0;
cout<<s5<<5<<s8<<s5<<s1<<s6<<6<<s8<<s6<<s1<<s6<<7<<s8<<s7<<s1;
cout<<s6<<8<<s7<<s<<7<<s9<<s<<1<<s6<<9<<s8<<s9<<s1<<s4<<s0;
cout<<s5<<10<<s8<<s10<<s1<<s6<<11<<s8<<s11<<s1<<s4<<s0;
cout<<s5<<12<<s8<<s12<<s1<<s6<<13<<s8<<s13<<s1<<s4<<s0;
cout<<s5<<14<<s8<<s14<<s1<<s6<<15<<s8<<s15<<s1<<s4<<s0;
cout<<s5<<20<<s8<<s20<<s1<<s4<<s0<<s5<<21<<s8<<s21<<s1<<s4<<s0<<s5<<22<<s8<<
s22<<s1<<s4<<s0;
cout<<s5<<23<<s8<<s23<<s1<<s4<<s0<<s5<<24<<s8<<s24<<s1<<s4<<s0<<s5<<25<<s8<<
s25<<s1<<s4<<s0;
cout<<s5<<26<<s8<<s26<<s1<<s4<<s0<<s5<<27<<s8<<s27<<s1<<s4<<s0<<s5<<28<<s8<<
s28<<s1<<s4<<s0;
cout<<s5<<29<<s8<<s29<<s1<<s4<<s0<<s5<<30<<s8<<s30<<s1<<s4<<s0<<s5<<31<<s8<<
s31<<s1<<s4<<s0;
cout<<s5<<32<<s8<<s32<<s1<<s4<<s0<<s5<<33<<s8<<s33<<s1<<s4<<s0<<s5<<34<<s8<<
s34<<s1<<s4<<s0;
cout<<s5<<35<<s8<<s35<<s1<<s4<<s0<<s5<<36<<s8<<s36<<s1<<s4<<s0;
cout<<s20<<s0<<s21<<s0<<s22<<s0<<s23<<s0<<s24<<s0<<s25<<s0<<s26<<s0<<s27<<s0
<<s28<<s0;
cout<<s29<<s0<<s30<<s0<<s31<<s0<<s32<<s0<<s33<<s0<<s34<<s0<<s35<<s0<<s36<<s0
;
cout<<s14<<s0<<s15<<s0;
return 0;
}
source code when run) in 100% ansi c++, without using any c-library
functions (such as printf), and not making any assumptions on the character
set.
Any comments? bugs? ideas on how to shorten it?
Emlyn
#include <string>
#include <iostream>
using namespace std;
int main() {
string s = "s", s0 = "\n", s1 = "\"", s2 = "\\", s3 = "n", s4 = ";";
string s5 = " string s", s6 = ", s", s7 = " = ", s8 = s7+s1, s9 = "+";
string s10 = "#include <string>", s11 = "#include <iostream>";
string s12 = "using namespace std;", s13 = "int main() {";
string s14 = " return 0;", s15 = "}";
string s20 = " cout<<s10<<s0<<s11<<s0<<s12<<s0<<s13<<s0;";
string s21 = "
cout<<s5<<s8<<s<<s1<<s6<<0<<s8<<s2<<s3<<s1<<s6<<1<<s8<<s2<<s1<<s1<<s6;";
string s22 = "
cout<<2<<s8<<s2<<s2<<s1<<s6<<3<<s8<<s3<<s1<<s6<<4<<s8<<s4<<s1<<s4<<s0;";
string s23 = "
cout<<s5<<5<<s8<<s5<<s1<<s6<<6<<s8<<s6<<s1<<s6<<7<<s8<<s7<<s1;";
string s24 = "
cout<<s6<<8<<s7<<s<<7<<s9<<s<<1<<s6<<9<<s8<<s9<<s1<<s4<<s0;";
string s25 = " cout<<s5<<10<<s8<<s10<<s1<<s6<<11<<s8<<s11<<s1<<s4<<s0;";
string s26 = " cout<<s5<<12<<s8<<s12<<s1<<s6<<13<<s8<<s13<<s1<<s4<<s0;";
string s27 = " cout<<s5<<14<<s8<<s14<<s1<<s6<<15<<s8<<s15<<s1<<s4<<s0;";
string s28 = "
cout<<s5<<20<<s8<<s20<<s1<<s4<<s0<<s5<<21<<s8<<s21<<s1<<s4<<s0<<s5<<22<<s8<<
s22<<s1<<s4<<s0;";
string s29 = "
cout<<s5<<23<<s8<<s23<<s1<<s4<<s0<<s5<<24<<s8<<s24<<s1<<s4<<s0<<s5<<25<<s8<<
s25<<s1<<s4<<s0;";
string s30 = "
cout<<s5<<26<<s8<<s26<<s1<<s4<<s0<<s5<<27<<s8<<s27<<s1<<s4<<s0<<s5<<28<<s8<<
s28<<s1<<s4<<s0;";
string s31 = "
cout<<s5<<29<<s8<<s29<<s1<<s4<<s0<<s5<<30<<s8<<s30<<s1<<s4<<s0<<s5<<31<<s8<<
s31<<s1<<s4<<s0;";
string s32 = "
cout<<s5<<32<<s8<<s32<<s1<<s4<<s0<<s5<<33<<s8<<s33<<s1<<s4<<s0<<s5<<34<<s8<<
s34<<s1<<s4<<s0;";
string s33 = "
cout<<s5<<35<<s8<<s35<<s1<<s4<<s0<<s5<<36<<s8<<s36<<s1<<s4<<s0;";
string s34 = "
cout<<s20<<s0<<s21<<s0<<s22<<s0<<s23<<s0<<s24<<s0<<s25<<s0<<s26<<s0<<s27<<s0
<<s28<<s0;";
string s35 = "
cout<<s29<<s0<<s30<<s0<<s31<<s0<<s32<<s0<<s33<<s0<<s34<<s0<<s35<<s0<<s36<<s0
;";
string s36 = " cout<<s14<<s0<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