“无法解决...”在 NetBeans 6.7.1、Linux、C++ 中

发布于 2024-08-05 08:53:11 字数 871 浏览 3 评论 0原文

我正在与一个小组合作开发 NetBeans 中的 C++ 项目。

由于某种原因,即使已包含正确的库,NetBeans 仍将“string”、“endl”、“cout”等内容报告为“无法解析”。

该项目按预期编译并运行,因此归根结底,这没什么大不了的,只是将所有内容都标记为错误使其变得非常烦人。

我还没有找到任何关于这个错误的信息。只是博客中的一个模糊参考。还有其他人经历过吗?

显然它并不广泛,因此必须有一个设置/配置导致它。有谁知道谁可以阻止这种情况发生吗?

编辑:

不,这些“错误”仅出现在 IDE 中。该代码编译良好并运行。开发人员使用了“using namespace std;”所以应该没有问题。 NetBeans IDE 似乎有错误。

示例代码:

#include <stdlib.h>
#include <string>
#include <iostream>

using namespace std;

int main(int argc, char** argv)
{
   string test;
   test = "Why?";

   cout << test << endl;

   return (EXIT_SUCCESS);
}

此代码编译并打印出“为什么?”但在 IDE 中将“string”、“cout”和“endl”标记为错误。显式使用 std:: 没有任何区别

清理编辑:

对于任何感兴趣的人,几天后我为 NetBeans 提供了 6 个更新。安装此更新后,尽管代码没有改变,但问题得到了纠正。所以,显然这是一个 NetBeans 错误。

I am working with a small group on a C++ project in NetBeans.

For some reason, NetBeans is reporting things like "string", "endl", "cout" as "Unable to Resolve" even though the correct libraries have been included.

The project compiles and runs as expected, so at the end of the day, it is no big deal, it is just that having everything marked as an error makes it quite annoying.

I haven't been able to find anything on this bug. Just one vague reference in a blog. Has anyone else experienced it?

Obviously it isn't wide-spread, so there must be a setting/configuration that causes it. Does anyone know who to prevent this from happening?

EDIT:

No, these "errors" are solely in the IDE. The code compiles fine and runs. The developer has used "using namespace std;" so there should be no issues. It appears that the NetBeans IDE is buggy.

Sample code:

#include <stdlib.h>
#include <string>
#include <iostream>

using namespace std;

int main(int argc, char** argv)
{
   string test;
   test = "Why?";

   cout << test << endl;

   return (EXIT_SUCCESS);
}

This code compiles and prints out "Why?" but has "string", "cout" and "endl" marked as errors in the IDE. Explicitly using std:: makes no difference

Clean up Edit:

For anyone interested, a few days later I had 6 updates available for NetBeans. After installing this updates, the problem was rectified, despite the code not changing. So, apparently it was a NetBeans bug.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

遗忘曾经 2024-08-12 08:53:11

嗯..同样的事情也发生在我身上。有一次我启动 NetBeans,它只是强调了我对 openGL(gl、glu 和 glut)的所有调用,而且我无法消除这些错误。它编译得很好(+自上次没有显示错误以来,我没有更改代码中的任何内容)

读完这篇文章后,我检查了更新,更新了,现在它表明没有错误:)这很奇怪,因为我定期更新..

< b>编辑: nvm,现在它们再次加下划线:(

hmm.. this same thing just happened to me. One time I started NetBeans up it just underlined all my calls to openGL (gl, glu and glut), and I couldn't get rid of the errors. It compiled just fine (+ I did not change anything in the code since the last time it showed no errors)

After reading this post I checked for updates, updated and now it indicates no errors :) it's weird cuz I update regularly..

EDIT: nvm, now they are underlined again :(

深海夜未眠 2024-08-12 08:53:11

尝试 std::stringstd::endlstd::cout 等。

或者,

using std::string;
using std::endl;
using std::cout;

在源文件的开头、之后你包括图书馆。也许您的 IDE 将它们标记为错误,但仍然使用标准命名空间。

您也可以只使用

using namespace std;

,但这通常是一个坏习惯,因为它会使全局名称空间变得混乱,并且最终可能会出现歧义(标准名称空间很大)。就我个人而言,我只是将 std:: 放在我的小项目中的所有内容之前,并在项目或我在较大项目中使用它的块中添加 using std::______

无论如何,这就是错误听起来的样子,但是(至少根据我的经验)如果这是问题所在,程序应该无法编译。

根据您的编辑:
如果您收到的错误仅来自 IDE,也许您的模式错误或其他原因?您在示例中发布的代码是足够简单的 C++,任何愿意使用 C++ 的编译器或 IDE 都可以毫无问题地处理它。如果您描述的错误来自您的编译器,则意味着您没有包含命名空间,或者您尝试使用 C 编译器编译 C++ 代码 - 也许 netbeans 认为您正在编写 C?

Try std::string, std::endl, std::cout, etc.

Or,

using std::string;
using std::endl;
using std::cout;

at the beginning of your source file, after you include the libraries. Maybe your IDE is flagging them as errors but then using the standard namespace anyways.

You can also just use

using namespace std;

but that is generally a bad habit as it clutters the global namespace, and you can end up with ambiguities (the standard namespace is big). Personally, I just put std:: before everything in my small projects, and a using std::______ in the project or blocks where I use it in larger ones.

Anyways, that's what the error sounds like, but (at least in my experience) the program should fail to compile if this is the problem.

Per your edit:
if the errors you get are coming only from the IDE, maybe you have it in a wrong mode or something? The code you posted in your example is simple enough C++ that any compiler or IDE which is willing to work with C++ would handle it no problem. If the errors you described came from your compiler, it would mean that you either didn't include the namespace or you were trying to compile C++ code with a C compiler -- maybe netbeans thinks you're writing C?

窝囊感情。 2024-08-12 08:53:11

对于感兴趣的人,几天后我为 NetBeans 提供了 6 个更新。安装此更新后,尽管代码没有改变,但问题得到了纠正。所以,显然这是一个 NetBeans 错误。

For anyone interested, a few days later I had 6 updates available for NetBeans. After installing this updates, the problem was rectified, despite the code not changing. So, apparently it was a NetBeans bug.

霊感 2024-08-12 08:53:11

FWIW 我在 Ubuntu 10.04 上使用 Netbeans 6.8 时遇到了同样的问题。令人沮丧的是,Netbeans 还告诉我,帮助中的内容是最新的 -->检查更新菜单(因为这是 Ubuntu 的当前版本)。

通过 synaptic/aptitude 删除 Netbeans 并手动下载并安装最新版本 (6.9.1) 也解决了我的问题。我希望商店里不会有更多这样的讨厌的事情......

现在我已经解决了这个问题并应用了 这个性能补丁,我已经有了一个非常好的 IDE,可以快速完成代码。遗憾的是,这种体验无法开箱即用,我在 Eclipse CDT 和 Netbeans 上花了相当多的时间,试图让一切顺利运行。

FWIW I had the same issue with Netbeans 6.8 on Ubuntu 10.04. Frustratingly Netbeans told me also that it was up to date in the Help --> Check for updates menu (as this is the current version for Ubuntu).

Removing Netbeans via synaptic/aptitude and manually downloading and installing the latest version (6.9.1) also resolved the issue for me. I'm hoping there aren't more such nasties in store...

Now that I've resolved this and applied this performance patch, I've got a really sweet IDE set up with fast code completion. It's a shame this experience isn't available out of the box, I spent a fair bit of time on both Eclipse CDT and Netbeans trying to get things working well.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文