0

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;
}
frlan
  • 6,950
  • 3
  • 31
  • 72
Mohamadreza
  • 313
  • 3
  • 6
  • 22
  • Please post some code so we can advise. – Anon Mail Nov 23 '15 at 16:42
  • I don't even know what geany is, but that one line of code you posted is a perfectly fine line of C++ code. So the problem is something beyond that. Probably something with your compiler environment. Either post an [MCVE](http://stackoverflow.com/help/mcve) or start talking about your environment. – Moby Disk Nov 23 '15 at 17:13
  • Simillar question http://stackoverflow.com/questions/19500018/unable-to-compile-simple-c-program-in-linux-mint-15 – MTP Nov 23 '15 at 17:16
  • Have you saved you file as .c/.C instead of .cpp? If a, rename it or manual change to C++ via Document->Set Filetype – frlan Nov 24 '15 at 15:03

1 Answers1

2

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++

milch
  • 986
  • 8
  • 13
  • Geany is detecting the filetype by file's extension. So if the file is called .c oder .C it might reconized it as plain C file. To fix this, rename it to .cpp (I guess it's the default) or manual change filetype to change between preconfigured g++/gcc usage. – frlan Nov 24 '15 at 15:05