Use C++ 14 as default version

cplusplus

#1

hello is anyone here can help me with this code it doesn’t work here online but on visual studio works correctly how can i make default to work ?

#include<iostream>

using std::cin;
using std::cout;
using std::endl;
using std::string;

int main()
{
    string str("Some string");
    for (auto c : str)
        cout << c << endl;

    return 0;
}

#2

Cloud9 uses the gcc compiler which by default doesn’t work with C++ 11. This means the auto keyword won’t work. You can make it work by following the instructions here: https://docs.c9.io/docs/writing-a-c-app


#3

Yes, it will work because the code snippet above is C++ 11 code. But C++ 14 features are currently not supported, because this would require a gcc 5.x version. The actual gcc version used is 4.8.4


#4

You can install gcc 5+ if you like with the following commands:

sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get install g++-5 

Then you can compile your files with g++-5 -std=c++14 <filename>. I just tested your file and it compiled successfully. I’ve added this information and how to modify the runner to our documentation page too: https://docs.c9.io/docs/writing-a-c-app


#5

So here is my runner for c++14 (below). I installed gcc 5+ as shown in your post and can compile correctly from the command line as also shown in your post. I tried to edit the c++ runner (below) and I get an error when running from the editor. The only c++14 code I tested was int x = 1’000’000; This generates a compiler error when using the runner below. (I probably understand less than half of the runner.)

Thanks for any help, Peter

// This file overrides the built-in C++ (simple) runner
// For more information see http://docs.c9.io:8080/#!/api/run-method-run
{
  "script": [
    "set -e",
    "if [ \"$debug\" == true ]; then ",
    "/usr/bin/g++5 -ggdb3 -std=c++14 $file -o $file.o",
    "chmod 755 \"$file.o\"",
    "node $HOME/.c9/bin/c9gdbshim.js \"$file.o\" $args",
    "else",
    "/usr/bin/g++5 -std=c++14 $file -o $file.o",
    "chmod 755 $file.o",
    "$file.o $args",
    "fi"
  ],
  "info": "Running $file",
  "debugger": "gdb",
  "$debugDefaultState": false,
  "env": {},
  "selector": "^.*\\.(cpp|cc)$"
}

#6

sounds like runner file didn’t get applied somewhy, try renaming it and choosing the new one from the dropdown.
also not that there is a typo in your code instead of /usr/bin/g++5 it should be g++-5


#7

That worked, fixed the typo and saved with new name.

Thank you for the quick response! -Peter