سؤال

My IDE (NetBeans) thinks this is wrong code, but it compiles correctly:

std::cout << "i = " << i << std::endl;
std::cout << add(5, 7) << std::endl;
std::string test = "Boe";
std::cout << test << std::endl;

It always says unable to resolve identifier .... (.... = cout, endl, string);

So I think it has something to do with the code assistance. I think I have to change/add/remove some folders. Currently, I have these include folders:

C compiler:

/usr/local/include
/usr/lib/gcc/i486-linux-gnu/4.4.3/include
/usr/lib/gcc/i486-linux-gnu/4.4.3/include-fixed
/usr/include

C++ compiler:

/usr/include/c++/4.4.3
/usr/include/c++/4.4.3/i486-linux-gnu
/usr/include/c++/4.4.3/backward
/usr/local/include
/usr/lib/gcc/i486-linux-gnu/4.4.3/include
/usr/include

What could be causing this, and how can I make NetBeans mark it as valid code?

هل كانت مفيدة؟

المحلول

It works fine for me. I'm using NetBeans 6.8; the only undefined reference I got was for the add() function.

Can you test with a new project to see if you can reproduce the problem?

EDIT (reply):

Yep, tested on Linux. No includes added in project properties.

In the global C/C++ options I have an extra include path for C, /usr/include/i486-linux-gnu.
For C++ I have:

/usr/include/c++/4.4
/usr/include/c++/4.4/i486-linux-gnu
/usr/include/c++/4.4/backward
/usr/local/include
/usr/lib/gcc/i486-linux-gnu/4.4.3/include
/usr/lib/gcc/i486-linux-gnu/4.4.3/include-fixed
/usr/include/i486-linux-gnu
/usr/include

These are my defaults, haven't touched them. HTH I also use gcc-4.4.3 (Ubuntu 10.04).

نصائح أخرى

Do you have the proper includes?

If I remember correctly, you need to

#include <iostream>

Go to Tools->Options->C/C++->Build tools, it will show the compiler NetBeans is using. E.g.

    /usr/bin/g++

Typing in a terminal:

    $ whereis g++
    g++: /usr/bin/g++ /usr/bin/X11/g++ /usr/share/man/man1/g++.1.gz
    $ ls -al /usr/bin/g++
    lrwxrwxrwx 1 root root 7 Mar 13  2012 /usr/bin/g++ -> g++-4.6

Will show which version of the compiler Netbeans is using. If the libraries in the Code Assistance tab do not match, you need to change them for the ones of the right version. E.g.

    /usr/include/c++/4.6
    ...
    /usr/lib/gcc/i686-linux-gnu/4.6/include-fixed

and so on.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top