#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <string>
using namespace std;
int main()
{
ostringstream out;
ostringstream tmpstr;
tmpstr << "ritesh is here";
out << tmpstr.str().c_str();
out << endl;
cout << out.str();
if(tmpstr.rdbuf()!=NULL)
cout << "tmpstr not null" <<endl;
else
cout << "tmpstr null" <<endl;
delete tmpstr.rdbuf(); // This line gives me segmentation fault
cout <<"deleted" << endl;
}
该行delete tmpstr.rdbuf();
给出了分段错误。我猜 rdbuf 返回 char* 指针,因此 . 我可以对其使用删除来释放分配给的内存空间tmpstr
我在某处错了吗?