Error Message

Hi I am a beginner C++ person and I tried to compile my first Hello World Program. I am using the Sams Teach Yourself C++ book to learn C++ and I have Visual 2012 Professional. I created a new file using the Win32 Console Application and then checked off Empty Project. I made a new source file and entered the Hello World code as follows;

# include <iostream.h>

int main()
{
cout << "Hello World\n";
return 0;

}

and when I did a Build I got this message;

========= Build: 0 succeeded, 0 failed, 1 up-to-date, 0 skipped ==========

When I tried to run it using Ctrl F5 I got this message;
"C:\Users\Carl\Documents\C++Stuff\Sams_Project1\Debug\Sams_Project1.exe" is not recognized as an internal or external command, operable program or batch file

What do I need to do to compile and run this program properly? Thanks
Last edited on
i think you should write #include<iostream>
(without ".h"> )

Maybe the problem is this! :)
You should create a console application. By default MS VS inserts its header
#include "stdafx.h"
After it you should include your header

#include <iostream>

and other code.
Last edited on
Thanks Ok I changed the code to as follows

# include <iostream>
using namespace std;
int main()
{
cout << "Hello World\n";
return 0;

}

This seems to work but the DOS screen flashes too quickly to know for sure. How do I get to hold that screen so I can see the results
Kadaj I seem to have solved the problem but the DOS screen flashes so quickly. I see Hello World only for a split second. How do I get that screen to stay up and not flash away so quickly
It can not flashes too quickly if you use keys Ctrl+F5 in MS VS IDE..
Last edited on
Hi vlad. Yes I did use Ctrl + F5 and the screen only comes up for a millisecond. I do now do see the words Hello World but this will be a problem if I make more complicated programs
As I said create a new console project. The main file of the new project will contain header
#include "stdafx.h"

After pressing Ctrl+F5 your program will be launshed will wait until you press any key.

Last edited on
OK vlad I will try that. I also used the following code which worked too;

#include <stdio.h>

void PressEnterToContinue()
{
int c;
printf( "Press ENTER to continue... " );
fflush( stdout );
do c = getchar(); while ((c != '\n') && (c != EOF));
}

int main()
{
puts( "Hello World!\n" );
PressEnterToContinue();
return 0;
}
Hi vlad your solution worked too. Thanks
You can also try adding this line to your code:

#include <iostream.h>

int main()
{
cout << "Hello World\n";
system("pause");
return 0;

}
Thanks Nolan & Vlad & Kadaj
C++ seems to be a very cool language. Numerous ways to skin the cat. Any good books you can recommend that fast track learning of this language. I am going to try and become proficient in it and see if i can get some work doing C++ programming
Any good books you can recommend that fast track learning of this language.

Accelerated C++ seems to be what you're looking for.
Are any of you people employed doing C++ programming?
Are any of you people employed doing C++ programming?

Quite a few active members of this forum are employed, although that's a topic more suitable for Lounge.
I'm just a student, far from being employed. I'm taking a course that's using Deitel's C++ for Programmers.

http://www.deitel.com/Books/C/CforProgrammers/tabid/3382/Default.aspx

This is the very first programming language I've learned, but it does prove to be interesting thus far.
Topic archived. No new replies allowed.