0

I was writing a sample code on NetBeans and I realized that using std::foo does not work on NetBeans. It gives a "unresolved identifier error". This is the sample code below;

#include <cstdlib>
#include <iostream>
#include <vector> //Required whenever you use vectors

/*
 * 
 */
using std::vector;
using std::cout;
using std::endl;

int main(int argc, char** argv) {

    vector<int> integers (4, 100); // Creates a vector [100 100 100 100]

    cout << integers[0] << endl;

    return 0;
}

The code builds and runs but the error is still visible on the text page.

  • What is `std::foo` actually? – πάντα ῥεῖ Sep 23 '16 at 15:27
  • i just used std:: foo as an example. Like in my code, it does not recognize the "using std:: vector" or "using std::out" or "using std::endl" declarations at the top. I declare them this way so I do not have to use "using namespace std" as I been too that is bad practice – Olaniyi Jinadu Sep 23 '16 at 15:30
  • `using std::vector;` looks wrong without a type parameter. Also the code indexing isn't always reliable. – πάντα ῥεῖ Sep 23 '16 at 15:32
  • @πάνταῥεῖ I have tried this on different compilers and it worked fine but I am only having this issue with NetBeans. Also, the code runs and builds fine but the error is highlighted in the editor – Olaniyi Jinadu Sep 23 '16 at 15:33
  • Netbeans is an IDE, not a compiler. – πάντα ῥεῖ Sep 23 '16 at 15:34
  • http://stackoverflow.com/questions/14913243/netbeans-7-2-shows-unable-to-resolve-identifier-although-build-is-successful – SingerOfTheFall Sep 23 '16 at 15:34
  • to my experience netbeans isnt particularly c++ friendly, just ignore your IDE, when the compiler is right – 463035818_is_not_an_ai Sep 23 '16 at 15:35
  • @tobi303 I tried lol. the error highlighting just messes with me. Im tempted to just write it as std::cout << integers[0] << std::endl; instead because that doesn't show errors but I am planning on writing a lot of lines of code and that is just tedious – Olaniyi Jinadu Sep 23 '16 at 15:49
  • just stop being lazy or rely on autocompletion. Others may have different opinion but I would insist that `std::cout` is always prefereable to `cout`. Actually `cout` isnt the problem, but eg you cannot tell whether `find(...)` is a function full of bugs or not, while with `std::find(..)` you can be sure that the bug is somewhere else. – 463035818_is_not_an_ai Sep 23 '16 at 15:57
  • What type of NetBeans project do you use? – HEKTO Oct 17 '16 at 18:08

0 Answers0