I'm very new in Ubuntu and programming C++ on Ubuntu using Geany. The problem I have here is that: the classes i want to iclude to my project will receive an error, I type,
#include <vector>
the error given here is,
fatal error: vector: No such file or directory
also I cannot use namespace std,
typing using namespace std
returns the following error,
error: unknown type name 'using'
Here is the code:
#include <stdio.h> //no problem here
#include "stdlib.h" //no problem here
#include <vector> //this is a problem (lets say it returns error 1)
using namespace std; //this is a problem (lets say it returns error 2)
int main(int argc, char **argv)
{
return 0;
}
This sounds like you are using the wrong compiler to compile your C++ code. For example, by invoking gcc test.cpp
the C++ file is actually compiled as C and you receive errors such as the one you posted - there is no vector
header in C and there is also no using
keyword.
If you are using gcc
, the correct way to invoke the compiler to compile C++ is via the g++
symlink, i.e. g++ test.cpp
If you are using clang, the executable is called clang++
instead.
Both compilers support the -x
parameter to manually change the language to C++, although in that case you also have to specify that the compiler needs to link your files with the C++ standard library. For example: gcc -x c++ test.cpp -lstdc++