轻舟过
写了个输出自己源代码的程序

一下午就费在写这个程序上了,好累,各种转义字符看得我眼睛花

编译运行以下代码,得到的输出就是代码本身,是不是觉得有点神奇

[mw_shl_code=cpp,true]#include *本站禁止HTML标签噢*

using namespace std;

int main() {

string x = "\tstring temp = \"\";\n\tfor(int j = 0; j < (int)x.size(); ++j) {\n\t\tif(x[j] == \'\\\\\' || x[j] == \'\\\"\' || x[j] == \'\\\'\') {\n\t\t\ttemp += \"\\\\\";\n\t\t\ttemp += x[j];\n\t\t}\n\t\telse if(x[j] == \'\\n\')\n\t\t\ttemp += \"\\\\n\";\n\t\telse if(x[j] == \'\\t\')\n\t\t\ttemp += \"\\\\t\";\n\t\telse\n\t\t\ttemp += x[j];\n\t}\n\tstring a = \"#include *本站禁止HTML标签噢* \\nusing namespace std;\\nint main() {\\n\\tstring x = \\\"\" + temp + \"\\\";\\n\";\n\tcout << a + x << endl;\n\treturn 0;\n}";

string temp = "";

for(int j = 0; j < (int)x.size(); ++j) {

if(x[j] == '\\' || x[j] == '\"' || x[j] == '\'') {

temp += "\\";

temp += x[j];

}

else if(x[j] == '\n')

temp += "\\n";

else if(x[j] == '\t')

temp += "\\t";

else

temp += x[j];

}

string a = "#include *本站禁止HTML标签噢* \nusing namespace std;\nint main() {\n\tstring x = \"" + temp + "\";\n";

cout << a + x << endl;

return 0;

}[/mw_shl_code]

轻舟过
感觉有很多都是写死的东西
展开Biu

xswaqde 发表于 2012-11-1 14:18

感觉有很多都是写死的东西~~~

本来就是写死的啊

[查看全文]
xswaqde
感觉有很多都是写死的东西
展开Biu

感觉有很多都是写死的东西~~~

[查看全文]
轻舟过
大人用的神马编译器啊
展开Biu

Sekt 发表于 2012-11-1 10:01

ctrl+c跑完……报了34个错??

大人用的神马编译器啊=。=

报错可能是没有#include *本站禁止HTML标签噢* 的问题

反正我用g++不用include也可以的

[查看全文]
Sekt
大人用的神马编译器啊
展开Biu

ctrl+c跑完……报了34个错??

大人用的神马编译器啊=。=

[查看全文]
zy9967
偶是来膜拜的
展开Biu

偶是来膜拜的= =~

[查看全文]
Dou_Ga
Dou_Ga回复给帖子:4949048
展开Biu

路过········

[查看全文]
轻舟过
好像很有意思的样子
展开Biu

FrostA 发表于 2012-10-25 22:13

好像很有意思的样子、有时间自己也尝试下

其实说实话很蛋疼,纯geek向

[查看全文]
FrostA
好像很有意思的样子
展开Biu

好像很有意思的样子、有时间自己也尝试下

[查看全文]