【问题标题】:Why this snippet is giving me compilation error [closed]为什么这个片段给我编译错误[关闭]
【发布时间】:2013-07-10 05:48:56
【问题描述】:
#include<iostream>
using namespace std;

int main()
{
    ostream os=cout;
    os<<"ABC";

}

这给了我编译错误。

【问题讨论】:

  • 你试过ostream&amp; os = cout;吗?
  • 你遇到了什么错误?
  • 如果您认为您的问题足够琐碎以至于您不必复制错误,那么您为什么要先问?

标签: c++ output cout ostream


【解决方案1】:

试试这个:

#include<iostream>
using namespace std;

int main()
{
    ostream& os = cout;
    os << "ABC"<< endl;

}

ostream&amp; os = cout; 声明对 cout 的引用,称为 os

【讨论】:

    【解决方案2】:

    你肯定会得到一个错误,因为你不能直接将它分配给 count...你需要将它与 ostream 的引用链接...

    你能换行吗:

    ostream os=cout;

    ostream & os = cout

    希望对你有帮助...

    【讨论】:

    • 没关系@Nitin,我希望你现在已经解决了这个错误......如果你需要更多帮助来理解任何概念,请告诉我......
    猜你喜欢
    • 1970-01-01
    • 2021-04-22
    • 2012-05-23
    • 2012-02-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多