0

I'm a beginner with C++ and I'm currently trying to compile an easy program with Geany, but it doesn't recognize the type 'auto' because it's a C++11 extension, and then when execute the terminal shows this message: No such file or directory

this is the code

#include <iostream>
#include <array>
using namespace std;

typedef int type;
typedef array <type, 6> List;

bool belong(type element, List list);

int main()
{
  List mylist = {1,2,3,4,5,6};
  
  cout << belong(2, mylist) << endl;
  cout << belong(16, mylist) << endl;
  
  return 0;
}

bool belong(type x, List list)
{
    for (auto element : list){
        if (x==element) return true;
    }
    return false;
}

Can someone help me.

  • Add `-std=c++11` to your compile command. Optional, use something better than Geany. – sweenish Aug 16 '21 at 16:36
  • When you run `g++ --version`from the console (not geany) which version do you see? It must be very old if it does not accept C++11 by default. Anyway, try to change the [build options](https://wiki.geany.org/howtos/configurebuildmenu) in geany in order to add something like `-std=c++17` after `g++`. – prog-fh Aug 16 '21 at 16:38
  • Does this answer your question? [Compiling a .C file: Undefined symbols for architecture x86\_64](https://stackoverflow.com/questions/19572665/compiling-a-c-file-undefined-symbols-for-architecture-x86-64) – phuclv Aug 16 '21 at 16:51
  • @sweenish thank you very much!! Any suggestion to replace Geany? – Queenie07 Aug 16 '21 at 16:54
  • Depends on your platform and how much configuring you're willing to do. – sweenish Aug 16 '21 at 17:05
  • @sweenish I'm open to any suggestion. – Queenie07 Aug 16 '21 at 19:10
  • I know you're trying to be accommodating, but when I say it depends on your platform and willingness to configure, I mean it. I can't recommend Xcode if you're not on a Mac, nor can I recommend VS Community if you are. Personally, I use VS Code on my Mac and on Windows (connecting to a WSL instance). At work, I use vim, a CLI text editor. Both require a good amount of configuring and subsequently practice to get into a good flow. – sweenish Aug 16 '21 at 19:54

0 Answers0