WebSpartan
WebSpartan

Reputation: 186

C++ compiling and running in Sublime Text 2

I really like Sublime Text 2 for HTML/CSS and Python and I'm starting to learn C++ and I want to use Sublime Text 2. I have looked at a few tutorials on installing g++ in order to run C++ in Sublime Text 2.

This is my code:

// my first program in C++
#include <iostream>

int main()
{
  std::cout << "Hello World!";
}

And when I run it it says [Finished in 1.5s] but nothing got printed. I have added the environment variables path but nothing gets printed.

Upvotes: 2

Views: 1302

Answers (1)

OMGtechy
OMGtechy

Reputation: 8220

The problem is that you are pressing build, which compiles your source code into an executable but does not run it. The [Finished in ...s] you are seeing is how long the program took to compile.

What you need to do is build like you currently are, but then go to the directory where your source code is and run the executable file that's in there*. There is a run option within the editor, but it doesn't always work on Windows**.

*if the program closes instantly, try running it from the console or adding std::cin.get() to the end of your program
**often due to incorrect configuration

Upvotes: 5

Related Questions