6

Newbie here. I just got an error running from the terminal a C++ program I wrote: error: ‘stoi’ is not a member of ‘std’. They told me the compiler is too old.

I'm using Ubuntu 14.04.

My g++ version is 4.8.4.

How do I upgrade?

0

1 Answer 1

5

You don't need to upgrade. Specify the standards version to g++. For example, to compile an example program from cppreference.com:

$ g++ --version
g++ (Ubuntu 4.8.5-2ubuntu1~14.04.1) 4.8.5
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ g++ --std=c++11 -o test test.cpp
$ ./test
std::stoi("45") is 45
std::stoi("3.14159") is 3
std::stoi("31337 with words") is 31337
6
  • 1
    so every time I use g++ I need to add --std=c++11? Can't I make C++11 the default standard?
    – Pigna
    Feb 9, 2016 at 19:30
  • 2
    @Pigna If you run g++ that often, you should be writing Makefiles.
    – muru
    Feb 9, 2016 at 19:32
  • @muru: If your machine pre-dates the standard then an update is required. Example: c++17/c++1z just released a few months ago, and my machine does not support the standard because its a few years old. Your answer is a solution to the OP's particular use case, not the posed question Jun 17, 2017 at 17:24
  • 1
    @charlestoncrabb then you'd be looking for askubuntu.com/questions/466651/…. I don't really care about the posed question, because it's often the case that people think they want X when they want to solve Y.
    – muru
    Jun 17, 2017 at 17:29
  • @muru What if you are compiling someone else's code and can't edit the MakeFiles.
    – mjwrazor
    Jun 4, 2018 at 21:47

Not the answer you're looking for? Browse other questions tagged .