1
在一个旧的项目代码的安慰是如下语句:印刷使用的ostream和运营商<<
cout.operator<<("Hi...");
ostream.operator<<("Hi....");
它认为它可以写成followa,导致相同的输出:
cout << "Hi..";
我试图把这些语句放在main()中。但是,编译器会发出错误:
In function 'int main()':
11:3: error: 'ostream' was not declared in this scope
11:3: note: suggested alternative:
In file included from /usr/include/c++/4.9/ios:38:0,
from /usr/include/c++/4.9/ostream:38,
from /usr/include/c++/4.9/iostream:39,
from 2:
/usr/include/c++/4.9/iosfwd:136:33: note: 'std::ostream'
typedef basic_ostream<char> ostream;
,我不服气的另一件事是本声明的ostream可以直接调用操作< <。直接在cout可以呼叫运营商< <。
如果有些机构可以详细说明或解释如何,那么我将能够调试代码。
谢谢。
你可以[编辑]你的帖子来显示主要功能&包括? –
错误消息是没有名为'ostream'的变量。将第二行更改为'cout.operator <<(“Hi ....”);'或'static_cast(cout).operator <<(“Hi ....”);'。 –