views:

1182

answers:

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.

A: 

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
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
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
weird. There's nothing else I can think of
Carson Myers
A: 

Or

using namespace std;

if you are feeling a little lazy, pop it in instead of each individual "using std::". I am pretty sure the compiler just picks the bits it requires from the std namespace, so it isn't a performance hit, as you are not including the whole namespace every time.

YoungPony
-1: This is not a good piece of advice to give without a suitable warning as to whay it's generally a bad idea. cf. Carson Myers' answer.
Troubadour
Would you like to explain this is a bad idea? Possible problems may occur when using the definition multiple times in .cpp/.h files without checking if has not been defined before. Also i suppose using the std:: prefix in-code would make it more clear that the item has been called from the standard namespace.
YoungPony
it's a bad idea because it clutters the global namespace, and can cause naming ambiguities.
Carson Myers
A: 
David
A: 

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

I have just installed nb 6.7 on ubuntu and I have the same problem. If I try to update it, it says, the IDE is up to date... actually it finds nothing, also when I try to use my class ComplexNumbers in the main function.. any ideas?

Milka