Running Hello World in Codenvy(Updated October 2018 to reflect the changes in Codenvy)
Go to Codenvy
Sign Up or Login via the "GET STARTED" link.
Create a new Workspace. Give it a name like "CPP" and pick the stack C++. And Create the workspace.
Now expand the project in the Projects Explorer. You have a hello.cpp file. Double click on it and it already has everything to print Hello World!
Now let's create the Makefile with the following content. Note the tab before the g++.
g++ -std=gnu++11 hello.cpp
# Note that Makefiles require a tab before the g++
# It probably doesn't copy/paste well from this blog post
Create a new file (Project > New > File) with the name Makefile and paste the above lines. Make sure to change the space before the g++ to a tab!
Now you are ready to run the Hello World program. Click on the blue triangle and execute
Didn't run so great... We got a "run" tab in the Processes section at the bottom of the screen. And a nice big error. Looks like the C++ code is a bit off! Double click the hello.cpp to open up the file in the editor. Change the include statement on line 3 from iostream.h to iostream. Also cout is in the namespace std which isn't mentioned so prefix it with std:: Then hit the triangle and it works!
Interactive shellThat was fun but can we have an interactive shell? How can we make the program prompt the user for her name and play it back? We need a different runner!
Let's see. Here is an interactive C++ program:
std::cout << "Your name please: ";
std::cin >> name;
std::cout << "Hello: " << name << "!\n";
Let's run it with the blue triangle:
Looks like it used /dev/null as input. Not cool.
But we have the "Terminal". Let's use that and do the following steps:
Assuming you are on Linux and have run ssh-keygen then you have your public key in .ssh/id_rsa.pub Upload this to Codenvy. Go to Profile > Preferences > SSH > Machine > Upload Key and upload your public key. The Workspace then needs to be restarted Workspace > Stop > Start
In the Processes panel, next to the dev-machine there is the word SSH. Click on that and you receive connection information:
You can now cut&paste the ssh connection command into your local console. Then cd to /projects and you can run your program: