替换 istrstream(char* s, std::streamsize n) 构造函数?

Replacement for istrstream(char* s, std::streamsize n) constructor?

本文关键字:streamsize 构造函数 std istrstream char 替换      更新时间:2023-10-16

我有一个使用已弃用的 istrstream的代码块:

if((iss = new istrstream(inBuf, (int) msgLen)) == 0)
{
errId = ReadErr;
errStr = "Failed to allocate ostrstream";
D(cerr << "IpcSapBaseMsg: failed to allocate ostrstreamn");
}

我用istringstream更改了istrstream,但它没有奏效。

IpcSapBaseMsg.C:178:52:错误:从"msgLen_t {aka int}"到"std::ios_base::openmode {aka std::_Ios_Openmode}"的转换无效 [-fpermissive] if((iss = new istringstream(inBuf, (int( msgLen(( == 0(

是否有任何可行的替代方案或任何其他方法来解决我的问题?谢谢。

std::istringstream(std::string(inBuf, msgLen));

应该工作。如果inBuf以 null 结尾,则不需要msgLen参数 - 您可以

std::istringstream(inBuf);

不过,为什么new呢?我建议在这里发布问题之前查看参考资料。