字符串流问题
我无法编译以下 stringstreamm
stringstream qss;
qss.operator << "some text " ::stringstream.operator << DDateTime::date2Oracle(dFrom) ::stringstream.operator << " more text " ::stringstream.operator << DDateTime::date2Oracle(dUntil);
如果我只使用 <<
运算符而不使用 ::stringstream.operator
它会抱怨该运算符不明确,现在它会抱怨关于不正确的语法...
error C2143: syntax error : missing ';' before 'std::stringstream'
编辑:
错误 C2593:“运算符 <<”含糊不清 c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\ostream(434): 可能是 'std::basic_ostream<_Elem,_Traits>::_Myt &std::basic_ostream<_Elem,_Traits>::运算符 <<(std::basic_ostream<_Elem,_Traits>::_Mysb *)' 和 [ _Elem=字符, _Traits=std::char_traits ]
I cannot get the following stringstreamm to compile
stringstream qss;
qss.operator << "some text " ::stringstream.operator << DDateTime::date2Oracle(dFrom) ::stringstream.operator << " more text " ::stringstream.operator << DDateTime::date2Oracle(dUntil);
If I just use the <<
operator without the ::stringstream.operator
it complains about the operator being ambigious, now it complains about incorrect syntax...
error C2143: syntax error : missing ';' before 'std::stringstream'
EDIT:
error C2593: 'operator <<' is ambiguous
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\ostream(434): could be 'std::basic_ostream<_Elem,_Traits>::_Myt &std::basic_ostream<_Elem,_Traits>::operator <<(std::basic_ostream<_Elem,_Traits>::_Mysb *)'
with
[
_Elem=char,
_Traits=std::char_traits
]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
operator
关键字不属于此处,请将它们排除在外:这应该是完全有效且明确的,除非
date2Oracle
函数被模糊重载。为类型
T
实现operator<<
的正确模式是:The
operator
keywords don't belong here, leave them out:This should be perfectly valid and unambiguous, unless the
date2Oracle
function is ambiguously overloaded.The correct pattern for implementing
operator<<
for a typeT
is:嗯,很明显,无论
DDateTime::date2Oracle(dFrom)
返回什么类型都不会实现<<
运算符。所以你必须自己写一份。至于语法,首先你必须像调用函数一样调用它,它实际上是:
其次,
stringstream
定义在std
命名空间中,所以你有像std::stringstream
或::std::stringstream
一样编写。::stringstream
将在全局命名空间中查找它,并且那里没有定义这样的类。顺便说一句,
operator<<
通常作为自由函数实现,因此qss.operator<<
不起作用。Well, it is obvious that whatever type
DDateTime::date2Oracle(dFrom)
returns does not implement<<
operator. So you will have to write one yourself.As for the syntax, first of all you have to call it just like a function which it actually is:
And second of all,
stringstream
defined instd
namespace, so you have to write it likestd::stringstream
or::std::stringstream
.::stringstream
will look for it in global namespace and there is no such class defined there.BTW,
operator<<
usually is implemented as free function, soqss.operator<<
wouldn't work.变得非常时髦:
你可能会更好地了解歧义所在。
Go really funky:
And you'll probably get a better idea where the ambiguity is.
您需要像调用函数一样调用运算符。
You need to call the operator like a function.
显式转换为/构造字符串:
Cast to / construct string explicitly:
qss << 应该还不够“一些文字”<< DDateTime...
?Shouldn't be enough with
qss << "some text " << DDateTime...
?是什么阻止你做:
What's stopping you from doing: