我看了的IStream ::获得和疑问仍然挂起。比方说,我的分隔符实际上是NULL“\ 0”字符,在这种情况下会发生什么?从我读:

If the delimiting character is found, it is not extracted from the input sequence and remains as the next character to be extracted. Use getline if you want this character to be extracted (and discarded). The ending null character that signals the end of a c-string is automatically appended at the end of the content stored in s.

我宁愿“获得”了“的ReadLine”的原因是因为字符流提取到“流缓冲”的能力。

有帮助吗?

解决方案

如果你有这样的事情,然后分隔符将被卡住的输入流中:

std::string read_str(std::istream & in)
{
        const int size  = 1024;
        char pBuffer[size];
        in.getline(pBuffer, size, '\0');
        return std::string(pBuffer);
}

,如果你有“\ 0”作为分隔符和字符串不超过1024个字节大只是一个例子。

其他提示

我不”完全得到你的问题。

在MSDN网站,为get函数,它说:

  

在所有情况下,分隔符既不从流中提取的,也不由函数返回。 getline函数,相反,提取但不存储的分隔符。   在所有情况下,定界符既不从流中提取的,也不由函数返回。 getline函数,而相比之下,提取物但不存储的分隔符。

http://msdn.microsoft.com/ EN-US /库/ aa277360(VS.60)的.aspx

我不认为你将有一个问题,因为在MSDN网站告诉分隔符既不是从数据流中提取,也VY函数返回。

或者,也许我在这里缺少一个点?

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top