如何仅使用标准 C++ 编写代码来显示自身(将代码打印到控制台)而不使用任何外部库?
How can I write a code to show itself (print code to console) using standard C++ only without any external library?
#include <iostream> #include <fstream> #include <string> using namespace std; int main () { string line; ifstream sourceFile(__FILE__); if (sourceFile.is_open()) { while ( sourceFile.good() ) { getline (sourceFile,line); cout << line << endl; } sourceFile.close(); } else cout << "Unable to open source file"; return 0; }
多田:http://en.wikipedia.org/wiki/Quine_(computing)
从更务实的角度来说,几乎没有人这样做过。这是毫无意义的。如果您想分发源代码,只需像理智的人一样将其放入 tarball 或 zip 文件中即可。
Tada: http://en.wikipedia.org/wiki/Quine_(computing)
On a slightly more pragmatic note, almost no one ever does this. It's pointless. If you want to distribute source code, just put it into a tarball or zip file like a sane person.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
暂无简介
文章 0 评论 0
接受
发布评论
评论(2)
多田:http://en.wikipedia.org/wiki/Quine_(computing)
从更务实的角度来说,几乎没有人这样做过。这是毫无意义的。如果您想分发源代码,只需像理智的人一样将其放入 tarball 或 zip 文件中即可。
Tada: http://en.wikipedia.org/wiki/Quine_(computing)
On a slightly more pragmatic note, almost no one ever does this. It's pointless. If you want to distribute source code, just put it into a tarball or zip file like a sane person.