您的位置:首页 > 其它

strings命令没有预期的结果, 意味着异常!

2017-02-25 16:23 302 查看
       最近遇到这样一个问题, strings命令没有预期的结果, 我真没想通为什么!  感觉很奇怪, 于是不敢发布版本。  

       这时候, 偶然发现了一个编译期的错误提示, 感觉到有问题, 一起来看看简单的示例:

#include<iostream>
using namespace std;

int main()
{
string s = "hello world";
printf("%s", s);
string name = "lucy";

return 0;
}


     用strings a.out | grep lucy 居然查不到这个串, 真是奇怪。 编译期间有错误:

test.cpp: In function ‘int main()’:

test.cpp:7: warning: cannot pass objects of non-POD type ‘struct std::string’ through ‘...’; call will abort at runtime

     看到了abort, 整个人就不好了, 会core dump啊, 回头看代码, 发现了错误。 改正后, 用strings命令就能看到lucy了。 

     本次提前发现了一个core dump!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: