c++ stringde c_str()方法输出为空

程序运行过程中,会把IP地址转化为二进制,位数按照掩码位数,此二进制保存在str1数组内:

IP="10.166.50.0/23";
str1=changeIP(IP); //str=1100000010101000000000000000000
const char* pszOutput;
pszOutput=str1.c_str();
cout <<str1<<endl;
cout << pszOutput<<endl; //此语句输出为空

问题:最后一句 语句无法正常输出

c_str()这个函数是string类才有的函数,你只能对一个string类型的变量调用这个函数
你可以先把字符数组转为string再调用

string str = str1;
pszOutput = str.c_str();