我想在Windows中将字符串打印到命令行/终端,然后编辑/更改字符串并将其读回.谁知道怎么做?谢谢
print "Hell"
Hello! <---Edit it on the screen
s = raw_input()
print s
Hello!
Run Code Online (Sandbox Code Playgroud) 我知道这个网站上有很多类似的问题。我真的很喜欢以下链接中提到的解决方案:
\n\n\n\n经过一些修改,您可以在编译时包含文本文件,例如:
\n\nconstexpr const char* s = \n#include "file.txt"\nRun Code Online (Sandbox Code Playgroud)\n\n但是要使其工作,您必须向原始文件添加字符串文字前缀和后缀,例如
\n\nR"(\nThis is the original content,\nand I don\'t want this file to be modified. but i\n don\'t know how to do it.\n)";\nRun Code Online (Sandbox Code Playgroud)\n\n我的问题是:有没有一种方法可以使其工作但不修改 file.txt?
\n\n(我知道我可以使用命令行工具来制作副本,在副本前面添加和附加到副本,在编译后删除副本。我正在寻找比这更优雅的解决方案。希望不需要其他工具)
\n\n这是我尝试过的(但不起作用):
\n\n#include <iostream>\n\nint main() {\n constexpr const char* s =\n#include "bra.txt" // R"(\n#include "file.txt" //original file without R"( and )";\n#include "ket.txt" // )";\n std::cout << s << "\\n";\n return 0;\n}\n\n/opt/gcc8/bin/g++ -std=c++1z a.cpp\nIn file included from a.cpp:5:\nbra.txt:1:1: …Run Code Online (Sandbox Code Playgroud) 我在代码审查中注意到以下代码:
for (int i = 0; i < 50; ++i) {
switch(i) {
case 0:
return f1();
case 1:
return f2();
...
case 49:
return f50();
}
}
Run Code Online (Sandbox Code Playgroud)
我想知道是否有任何优雅的方式,例如使用宏来简化此代码(将其减少到几行):
谢谢.