5

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.

Dan McGrath
  • 41,220
  • 11
  • 99
  • 130

4 Answers4

1

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 :(

David
  • 11
  • 1
0

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?

Carson Myers
  • 37,678
  • 39
  • 126
  • 176
  • For "the program should fail to compile if this is the problem.", please see from the actual question, the following quote: "The project compiles and runs as expected" Thank you for attempting to help though. – Dan McGrath Sep 19 '09 at 11:36
  • Cannot be that either. It recognises classes we write correctly, as well as pass by reference. I cannot think of any language mode it could be where that was fine and string was not. – Dan McGrath Sep 19 '09 at 23:45
  • weird. There's nothing else I can think of – Carson Myers Sep 20 '09 at 08:05
0

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.

Dan McGrath
  • 41,220
  • 11
  • 99
  • 130
  • i have this problem too. I have NetBeans 7.1. But in Windows 7. Still not working. Code works fine. But errors appears. [here is my problem](http://stackoverflow.com/questions/20936513/c-in-netbeans-shows-errorsunable-to-resolve-identifiers-but-the-code-runs-fi) – prime Jan 05 '14 at 17:56
0

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.

Bryji
  • 1,206
  • 1
  • 13
  • 19