#include "stdafx.h"
#include <string>
#include <cstdlib>

int _tmain(int argc, _TCHAR* argv[])
{
    char* data = NULL;
    std::string str = data;

    system("pause");
    return 0;
}

 

如上代码,在某些情况下,可能给str赋值一个char*;char*

有可能是NULL,这个时候赋值给string,发生拷贝。string(const char*),传进去的是NULL。

在构造的时候strlen计算长度的时候发生崩溃

相关文章:

  • 2022-01-15
  • 2021-11-06
  • 2021-05-06
  • 2021-08-29
  • 2021-10-06
  • 2022-12-23
  • 2022-01-03
  • 2021-07-25
猜你喜欢
  • 2021-10-04
  • 2022-12-23
  • 2021-11-13
  • 2021-06-07
  • 2022-12-23
  • 2022-12-23
  • 2021-05-25
相关资源
相似解决方案