【发布时间】:2017-03-17 19:56:48
【问题描述】:
大家好,最近我开始更好地理解 c++,我发现了不同的问题,其中大多数问题开始变得清晰。我不明白的一件事是编译器在我尝试声明 ostream 或类声明中的每个流时发现的错误。例如
class Test{
stringbuff buff;
ostream out (&buff)
; }
编译器返回此错误消息:
expected identifier before ‘&’ token
另一个是当我尝试:
stringstream stream(std::in|std::out);
编译器返回
error: ‘std::ios<char, std::char_traits<char> >::in’ is not a type
stringstream out(ios::in|ios::out);
问题是为什么我不能在类声明中调用这些“函数”以及方法之王是什么。例如要更清楚地声明如何以与ostream o(方法)相同的方式在此使用相同的方法;
谢谢大家,对不起我的英语。
【问题讨论】:
-
ostream out{ &buff };将修复您的错误。我太累了,希望有人会写一个答案来解释原因和其他解决方案。 -
发布导致问题的真实代码,并用分号完成。