【问题标题】:C++ endl outputting a hexadecimal number [closed]C ++ endl输出十六进制数[关闭]
【发布时间】:2014-07-23 03:32:02
【问题描述】:

在使用 g++ 编译了大量程序后,endl; 突然出现了奇怪的行为。除了换行符之外,我还获得了十六进制数字的控制台输出。考虑到我可能有一些内存泄漏问题,我重新启动了在 Windows 之上的 VMWare 中运行的 Linux Mint Debian 版(最新)。问题仍然存在。下面是我的 g++ 版本(与之前的正常输出相比没有变化)和一个输出低于该版本的测试程序。

g++ 版本 (Debian 4.8.2-1) 4.8.2

void my_test_function(void)
{
  // cout << "my_test_function is working" << cout << endl;
  cout << "my_test_function is working\n" << cout << endl;
}

测试输出:

my_test_function is working 0x600ea8

【问题讨论】:

  • 不是endl 这样做,从 C++11 开始,它不应该编译。
  • 提示:你正在打印cout给它自己。
  • 尽量不要使用using namespace std;,这是一种不好的做法。
  • @MattMcNabb,是的,libstdc++ 没有做出改变(自从我上次检查以来)。 libc++ has

标签: c++ g++ endl


【解决方案1】:

你的陈述中有一个不正确的“cout”

尝试关注

void my_test_function(void)
{
  cout << "my_test_function is working" << endl;
}

【讨论】:

    【解决方案2】:

    抱歉,我不能在这里发表评论

    该行只需要如下所示

    cout << "my_test_function is working" << endl;
    

    【讨论】:

      【解决方案3】:

      固定代码:

      cout << "my_test_function is working" << endl;
      

      std::cout 是 ostream 的对象。你需要研究一下ostream的operator&lt;&lt;的签名和std::cout的定义。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-08-21
        • 1970-01-01
        • 2012-03-13
        • 1970-01-01
        • 2017-06-08
        • 2018-09-07
        • 2020-03-25
        • 2018-01-05
        相关资源
        最近更新 更多