error , Symbol 'vector' could not be resolved

后端 未结 12 835
心在旅途
心在旅途 2021-01-04 00:34

I am using eclipse in linux to develop a c++ application and I am getting this editor annotation error \"Symbol \'vector\' could not be resolved\" from the following code

相关标签:
12条回答
  • 2021-01-04 00:55

    In Eclipse, right-click on the project name...Select Index...Rebuild.

    0 讨论(0)
  • 2021-01-04 00:55

    adding #include< vector > and using namespace std; solved my problem

    0 讨论(0)
  • 2021-01-04 00:58

    You need to include the STL vector definition in your program. Put:

    #include <vector>
    

    at the top of your file and it should work.

    0 讨论(0)
  • 2021-01-04 00:58

    I feel that some library is missing or the paths are not set.

    Yes, this sounds like a linker error. Linkers deal with symbols.

    I explicitly downloaded STL but its of no use.

    Hopefully you mean libstdc++, GNU's implementation of the C++ Standard Library, and you probably shouldn't have done this. Your toolchain comes with the proper stdlib implementation.

    Do I have to re install GCC on my linux?

    Probably wise. And let this installation handle the standard library.

    Also, on the off-chance that you're playing with your compilation command line, remember to invoke g++ not gcc; g++ automatically links in the C++ runtimes and stdlib implementation, whereas gcc is designed for C.

    0 讨论(0)
  • 2021-01-04 00:59

    I had the same issue. I believe the problem arises from how std:: autocompletion is updated. Eclipse should be getting this from the Path and Symbols, but it could be buggy. I had to clean all Eclipse settings after upgrading gcc (thus, g++), since you're in Linux it's under your home folder ~/.eclipse/.

    Thus,

    1) Re-started Eclipse after cleaning ~/.eclipse/.

    2) checked that Path and Symbols (under right-click on project > General > Path and Symbols) included all the upgraded gcc and c++ include directories (vector should be under ./gcc/version/include/c++/version/)

    3) Rebuild index.

    4) Created a *.cpp file that includes the *.h where the error is showing. This will force Eclipse to backtrace dependencies for *.h.

    5) Rebuild index and/or restart a few times as required, now I can see vector at the end of std:: autocompletion.

    enter image description here(see picture)

    Hope it helps!

    0 讨论(0)
  • 2021-01-04 00:59
    #include <vector>
    

    Also, std::vector is template type, so you have to use it like

    std::vector<char> buffer;
    
    0 讨论(0)
提交回复
热议问题