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

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

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

[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

@21#果然很闲

[查看全文]
暮零天晨
其实后续的
展开Biu

轻舟过 发表于 2012-7-28 21:23

其实后续的VC++2005、2008、2010之类还是不错的

用DEVcpp成功运行了……

不过在使用字符串string的时候,文件开头不是必须要包含string的头文件吗?

[查看全文]
轻舟过
暮零天晨
展开Biu

暮零天晨 发表于 2012-7-28 21:03

因为我们老师给的所以就一直在用

那样的话用什么比较好?

其实后续的VC++2005、2008、2010之类还是不错的

[查看全文]
暮零天晨
建议不要用
展开Biu

轻舟过 发表于 2012-7-28 18:11

建议不要用vc++6.0,太老太老的东西了,很多已经不符合新标准了

因为我们老师给的所以就一直在用

那样的话用什么比较好?

[查看全文]
轻舟过
暮零天晨
展开Biu

暮零天晨 发表于 2012-7-28 18:09

vc++6.0

建议不要用vc++6.0,太老太老的东西了,很多已经不符合新标准了

[查看全文]
暮零天晨
我这可以的阿
展开Biu

轻舟过 发表于 2012-7-28 13:14

我这可以的阿,你用的什么编译器

vc++6.0

[查看全文]
轻舟过
体系得东西
展开Biu

Sin.re 发表于 2012-7-28 14:25

类似vm体系得东西 不过不局限于pcode解释

了解了

[查看全文]
Sin.re
本来就没有实际用处的
展开Biu

轻舟过 发表于 2012-7-28 11:22

本来就没有实际用处的

你说的那个是什么呢?

类似vm体系得东西 不过不局限于pcode解释

[查看全文]