c++中使用string代替new

来源:互联网 发布:复旦大学网络教育专业 编辑:程序博客网 时间:2024/06/05 15:39

对于在函数内申请空间常用的就是new一个区域,然后使用,

问题是释放的时机,其实习惯使用智能指针来说这个也都不是问题

个人常使用的就是用string,例如


return_type func(***){


                std::string buf(lensrc, 0);

                Byte * pbyte = (Byte*)&buf[0];

                /*

                      使用pbyte

                */


             return ***

}