0

I have been assigned to try and figure out how to write a program that prints itself. So far, this is what I've been able to come up with:

#include <iostream>
#include <fstream>
#include <cstring>

using namespace std;

ifstream in_stream;

int main()
{
string quine;

in_stream.open("main.cpp");
in_stream >> quine;
cout << quine << endl;

return 0;
}

I'm still fairly new to programming, so I can't figure out how to make it output more than just the first line. Any help would be greatly appreciated.

pfnuesel
  • 14,093
  • 14
  • 58
  • 71
  • Learn about loops. Then learn [why is `iostream::eof` inside a loop condition considered wrong](http://stackoverflow.com/questions/5605125/why-is-iostreameof-inside-a-loop-condition-considered-wrong). Also, [a good beginners book](http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list) might help too. – Some programmer dude Apr 06 '16 at 17:02
  • 1
    that's not really a quine, a quine can't open itself! To be honest, you probably won't figure out how to do this yourself as the solution itself uses mainly C elements, and i am not aware of a solution that utilizes any c++ utilites. – Nowhere Man Apr 06 '16 at 17:04
  • A quine cannot open any files for reading, so this isn't one. – n. m. could be an AI Apr 06 '16 at 17:10
  • @NowhereMan there's no "the" solution. You can write a quine in any sufficiently rich language, including those that have nothing in common with C. You can certainly write one in a pure STL-boasting pointer-eschewing C++. – n. m. could be an AI Apr 10 '16 at 07:41

0 Answers0