C++ std::string 不可初始化为NULL

c++ 给std::string 赋值 NULL 运行报错 , 编译正常

错误截图:

 

 

字符串不可以初始化为NULL,虽然能通过编译,但是会出现运行错误 ,可以赋值为 "" (空字符串);

示例 :

std::string res1 = NULL    ; //  错误的
std::string res2 = ""      ; //  好使的

 

posted on 2020-02-26 10:51  hi-gdl  阅读(2086)  评论(0编辑  收藏  举报

导航