【问题标题】:strlen was not declared in this scope - C++strlen 未在此范围内声明 - C++
【发布时间】:2010-12-30 17:38:47
【问题描述】:

我需要在我的 ubuntu 中安装一个模拟器。它是用 C++ 编写的,当我尝试运行 make 时,我收到此错误 strlen was not declared in this scope。有什么办法可以克服这个错误?

【问题讨论】:

  • 任何人都知道为什么这个错误不会在某些系统上发生,例如gcc 4.5.3 32 位 Linux?
  • @gcbenison: gcc 是一个 C 编译器,它不需要包含“c”库(即cstringcstdlib 等等)。但是g++ 是一个 C++ 编译器确实需要包含它们。

标签: c++ ubuntu


【解决方案1】:

应该这样做:

#include <cstring>

【讨论】:

  • 我也得到了 lrand48 is not declared in this scope 错误。你能帮帮我吗?
  • @Vivek:根据google#include &lt;cstdlib&gt; 可以提供帮助
【解决方案2】:
#include <cstring>

您的程序也可能正在寻找::strlen 而不是std::strlen。如果是这种情况,请尝试

using std::strlen;

【讨论】:

    【解决方案3】:

    您是否安装了所有需要的软件包?

    1. 试试 g++ --version 看看有没有什么作用。
    2. 检查 /usr/lib/include/ 中的 string.h。

    如果这些东西不存在,您需要检查是否安装了正确的软件包。

    【讨论】:

    • 现在真的,如果没有编译器就无法访问strlen() 有什么好抱怨的?
    • 住在电脑里的魔法精灵会。他们还对似乎出现然后在没有干预的情况下消失的大多数错误负责。
    猜你喜欢
    • 2010-12-17
    • 1970-01-01
    • 2021-07-17
    • 2015-08-21
    • 2015-08-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多