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.

5
  • 1
    Try std::cout << "Hello World!" << std::endl;
    – OMGtechy
    Commented Mar 19, 2014 at 23:26
  • Just tried that and It still says [Finished in 0.8s]
    – WebSpartan
    Commented Mar 19, 2014 at 23:28
  • 1
    Are you pressing build by any chance?
    – OMGtechy
    Commented Mar 19, 2014 at 23:30
  • I feel like a complete idiot now. I must be too used to python building. Yes I was pressing ctrl + b. Thanks
    – WebSpartan
    Commented Mar 19, 2014 at 23:34
  • No problem, I'll write an answer up and if you'd mark it as the solution I'd appreciate it :)
    – OMGtechy
    Commented Mar 19, 2014 at 23:34

1 Answer 1

5

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

1
  • When I choose the run option it seems as if it compiles then runs automatically, thanks you.
    – WebSpartan
    Commented Mar 19, 2014 at 23:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.