1. ホーム
  2. c++

basic_string::_S_construct NULL は有効ではない

2022-02-08 01:12:46
The error message reads:
An instantiation logic error caused the program to abort.
NULL cannot be used in the what() function to construct a basic_string object.

Here is a demonstration of how the error works:
============================
#include <string>
using namespace std;

void main(void)
{
 //string a(NULL);//wrong usage
 //string b = NULL;//wrong usage
 string a("");//correct usage
 string b = "";//correct usage
 string c;//correct usage

 a = "aaa";
 b = "bbbbbb";
 c = "ccc";
 printf("a = %s\nb = %s\nc = %s\n",a.c_str(),b.c_str(),c.c_str());

getchar();
}
================================


basic_string::_S_construct NULL は有効ではありません。

...  std::string  myStr1(0);  //I was expecting to create a string with the value "0" for me  std::string  myStr2  0;  //another of my sb's attempts //The right way to do it  std::string  myStr3("0");  std::string  myStr4=  "0"; //The right way to do it  std::string  myStr3("0");  std::string  myStr4=  "0";