"Hello world" - yeah I know but I just started...

Hi guys...

Just bought a book by Mike McGrath - C++ Programming in Easy Steps 3rd edition (probs a little out of date!) to make a start in learning C++, as I'm looking to get into the games industry and most engines seem to be C++ (I'm learning Digital arts and this is just to boost my CV! Plus I'm interested in Linux too so that's why I'm not using visual c++ express either)

I'm using the latest MinGW compiler as advised in the book and I don;t seem to be getting an output for the following code:

1
2
3
4
5
6
7
8
9
10
11
#include <iostream>
using namespace std ;

//A C++ Program to Output a greeting

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


it seems to work but doesn't display anything in the cmd window...

If anyone could explain why this isn't displaying anything it would help, and I don't wanna sound like an arse or anything but if you're going to chuck a load of code at me please could you explain what it does cause I have a tendancy to just chuck things in without understanding what they do...

Ta peeps!
Does cmd open at all?

If not, try;
cin.ignore(80, '\n');
And it'll stop there until you press Enter.
sorry... forgot to add that I'm running the file from cmd

1
2
3
..\C++>C++ hello.cpp

..\C++>


is basically what it's displaying
Cheers for the reply Splux

I added in the code you put up on line 9, between cout and return...

still just comes back with no output... :(

when I tried running the exe it automatically creates the cmd window... well... A window pops up and closes too fast to see what's in it...
See the reference http://www.cplusplus.com/forum/beginner/1988/
@Vlad from Moscow.... I appreciate the help but I'm totally confused by that thread... I've not done any kind of programming before and I feel that whole thread is lost on me.... other than to avoid using system in anything.... which i tried anyway and got error: 'system' was not declared in this scope

Also forgot to add... the book is telling me to type the code into a notepad doc (currently using win7... meh...) and save as hello.cpp... running with the command c++ hello.cpp in the cmd
Last edited on
Step 1. Build hello (compile and link hello.cpp to produce the excecutable hello)
Step 2. Run hello
1
2
> g++ -std=c++11 -Wall -pedantic-errors -o hello hello.cpp 
> ./hello

or for executable hello.exe:
1
2
> g++ -std=c++11 -Wall -pedantic-errors -o hello.exe hello.cpp 
> ./hello.exe


Last edited on
hmm...

that seemed to work...

What does any of it mean?

EDIT:-----------------------------------------

Doh.... never tried running the executable from the cmd... works fine!

Sorry guys but thanks for all the help! I got there in the end!
Last edited on
Topic archived. No new replies allowed.