5

My program compiles fine, but Netbeans tells me "Unable to resolve identifier to_string."

I tried everything in "Netbeans 7.2 shows "Unable to resolve identifier" , although build is successful" and I set the "C++ standard" to "C++11" in the code assistance options.

This is the only function giving this problem so far. It is however also the first C++11 feature I am using, which leads me to believe it has something to do with Netbeans not understanding that I am using C++11, although I specify it explicitly in the code assistance menu.

Minimal example:

#include <string>
int main() {
    std::to_string(1);
}

EDIT: the same problem arises where using nullptr

EDIT2: I suddenly realized it might be important to mention that I do not use a generated Makefile, but SCons.

Community
  • 1
  • 1
Oebele
  • 581
  • 1
  • 4
  • 17
  • I would make sure it's a c++11 related issue by using something that's a newer language keyword, for example `int* testCpp11 = nullptr` and see if you still get problems. – shuttle87 Jun 06 '15 at 18:51
  • @shuttle87 `nullptr` is also marked with "unable to resolve identifer" – Oebele Jun 06 '15 at 19:31

7 Answers7

23

I know this question is seven months old but since it came up as the second result to a google search I'll tell the answer I came up with. For Netbeans at least. Go to your project properties and make sure you have you "C Compiler"->"C Standard" set to C11, and your "C++ compiler"->"C++ Standard" set to C++11. You have to set BOTH or it will still give false errors!

Robert Reinhart
  • 507
  • 4
  • 10
  • 1
    Just encountered the issue again with nullptr, tried your solution and it gives the correct highlighting now, so this seems to be the correct answer. – Oebele Feb 23 '16 at 12:59
  • Don't know how you found this but you saved me from going nuts :) – DarkTide May 20 '16 at 10:30
  • @Oebele This fixed my issue. I had TWO (!) different projects in Netbeans. In one I had both C++ compiler and C Compiler with C++11 and C11 respectively. In the other project I had both of them to the default. But I had the issue in the later (with the default compilers). When I changed the compilers for the first project, it immediately fixed my issue. Thanks. – LuissRicardo Nov 14 '16 at 07:44
  • This issue still exists in 8.2 on both Linux and Windows, even though the default (under Tools) is set up correctly. It's a little annoying that this has to be setup per project, but it seems to work even with c14 (not tried c17). – Rebirth Oct 29 '18 at 13:42
  • Yep. Still the same in NB 10. Wasted hours on that until I found this thread. – Peter Mar 16 '19 at 23:15
  • Another wrinkle to add to this solution: most of the files in my project had a C++ level set on the individually. I have no idea why, as I'm the only project user and I never did it. The solution was to open the xml project file and find all instances of the attribute "flavor2" on all the nodes and set them all to "0". a quick regex search and replace, save and ta-da, problem fixed. – Chris Holt Apr 29 '20 at 18:16
5

This will solve the problem:

  1. Right click on "Project".
  2. Select "Code Assistance".
  3. Clean C/C++ cache.
  4. Restart IDE.
סטנלי גרונן
  • 2,917
  • 23
  • 46
  • 68
Shreejit Paul
  • 51
  • 1
  • 1
  • This worked for me! I tried setting the compilers for C and C++ to v11, but it didn't work even after restarting Netbeans. But clearing the cache worked wonderfully! – Joe Dimig Apr 01 '20 at 17:36
2

Autocomplete and sometimes even syntax highlighting are always faulty with C++. The more you go in depth with C++ and C++11, the more Eclipse and Netbeans will start underlining everything with a red wavy line. Some of my (correct and perfectly compiling) programs are a huge red wavy line. I suggest you disable error markers altogether and you keep autocomplete, but in many cases it just won't work and you have to make the best of it.

gd1
  • 11,300
  • 7
  • 49
  • 88
  • 6
    Disabling features that don't work is not exactlly a solution is it?, what's the point of using an IDE full of helpful features to end up disabling, you should recommend then using a text editor instead of an IDE. – DarkTide May 20 '16 at 10:28
  • I agree it isn't a solution. But it is an answer because the reality is: Netbeans IDE just can't cope with all these complex abstractions. If this is not what you want, A different IDE/Application than Netbeans would be better suited. (I don't really know any much better ones though) – Eaton Emmerich Jul 21 '17 at 16:19
1

I had the same situation. This was occurred because I used .c file instead of .cpp

0

for Netbeans 8.2 (on Linux) only the following worked for me: Tools -> Options -> Code Assistance -> Macro Definitions: change:__cplusplus=199711L to:__cplusplus=201402L for C++14 or to __cplusplus=201103L for C++11

pte
  • 1
  • 1
0

I did all the above but what did the trick for me was recognizing that the Makefile had g++ rather than g++ -std=c++11.

J Lag
  • 25
  • 4
0

To resolve c++17 related 'Unable to resolve identifier' in latest netbeans 8.2 or 9 version, one may need to set the macro definition __cplusplus=201703L as the default C++14 standard macro definition unable to resolve those unexpected error messages appeared in the editor.