首页 > 编程语言 >A C++ program that prints itself

A C++ program that prints itself

时间:2023-04-07 12:57:43浏览次数:43  
标签:std prints string namespace itself program main cout

#include <iostream>
using namespace std;

int main() {
  string s = "  cout << \"#include <iostream>\\nusing namespace std;\\n\\nint main() {\\n  string s = \\\"\";\n  for (char i : s)\n    if (i == '\\n')\n      cout << \"\\\\n\";\n    else if (i == '\"')\n      cout << \"\\\\\\\"\";\n    else if (i == '\\\\')\n      cout << \"\\\\\\\\\";\n    else cout << i;\n  cout << \"\\\";\\n\" << s;\n}\n";
  cout << "#include <iostream>\nusing namespace std;\n\nint main() {\n  string s = \"";
  for (char i : s)
    if (i == '\n')
      cout << "\\n";
    else if (i == '"')
      cout << "\\\"";
    else if (i == '\\')
      cout << "\\\\";
    else cout << i;
  cout << "\";\n" << s;
}

标签:std,prints,string,namespace,itself,program,main,cout
From: https://www.cnblogs.com/recurphy/p/17295794.html

相关文章