kybookie
kybookie

Reputation: 41

"Hello, World!" won't print

Previously, I have been interested in learning C++ so I decided to go for "InfiniteSkills" training video (http://www.infiniteskills.com/training/learning-c-plus-plus.html) The instructor start by teaching "Hello World" as a basic as always.

Here is the code:

#include <iostream>
using namespace std;

int main()
{
    cout << "Hello, World!";
    return 0;
}

but after I build it using CodeBlocks it won't compile I have also tried using Sublime text too, but the result seems to be the same Any suggestion?

Image:

Upvotes: 2

Views: 3278

Answers (5)

Ikari
Ikari

Reputation: 1

I had this problem too but I was able to fix it by reinstalling the C++ plugin for VS Code. I think the iostream wasn't actually there originally.

Upvotes: 0

Bodi Osman
Bodi Osman

Reputation: 117

You should both add a newline command in your print function and some sort of pause.

#include <iostream>
using namespace std;
int main(){
  cout << "Hello World!\n" //calls for a newline
  cin.get(); //pauses until a key is pressed
  return 0;
}

Try this and see if it works

Upvotes: 0

kybookie
kybookie

Reputation: 41

I don't know the real solution for this problem. But my guess is because of the complier. I have test with CodeBlocks and Sublime Text 3 on mac both won't print "Hello World" for me. So I decided to test with another which is "Xcode" and it works! I don't know what the real problem is but if anyone have any problem like me you may want to try using another complier :)

Thank you everyone for your suggestion and happy coding!!!!

enter image description here

Upvotes: 0

thepace
thepace

Reputation: 2221

As per the comments, you are unable to see the output. Try this:

#include <iostream>
using namespace std;

int main()
{
    cout << "Hello, World!";
    cin.get(); // This waits for you to input something and allows you to see the input.
    return 0;
}

Upvotes: 0

Chris Maes
Chris Maes

Reputation: 37782

you should add a newline character to the end of the line you want to print. Probably you are not seeing your output because it is still in the buffer. As @Quirliom noted: It may not be the stdio buffer but Sublime buffering until new lines...

cout << "Hello, World!\n";

or

cout << "Hello, World!" << endl;

Upvotes: 1

Related Questions