Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / August 2007

Tip: Looking for answers? Try searching our database.

My Hello World failed!

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Anil Gupte - 14 Aug 2007 20:26 GMT
I have never been so embarassed! :-)  I have played with C++, and even
created a few simple programs, but decided to learn it properly.  So I crack
a book, get into Visual Studio and follow the instructions to create the
following program:

// HelloWorld.cpp : Defines the entry point for the console application.
//
#include <iostream>
using namespace std;
int main()
{
cout << "Hello World!" << endl;
return 0;
}

and I get an error:

c:\Projects\CPlus2\HelloWorld\HelloWorld.cpp(12): fatal error C1010:
unexpected end of file while looking for precompiled header directive

The code is exactly as shown in the book - (Visual C++ Step by Step by
Templeman and Olsen).  What gives?

Signature

Anil Gupte
www.keeninc.net
www.icinema.com

Carl Daniel [VC++ MVP] - 14 Aug 2007 20:32 GMT
> I have never been so embarassed! :-)  I have played with C++, and even
> created a few simple programs, but decided to learn it properly.  So
[quoted text clipped - 18 lines]
> The code is exactly as shown in the book - (Visual C++ Step by Step by
> Templeman and Olsen).  What gives?

Add

#include "stdafx.h" as the first non-comment line in your .cpp file.

OR

Right-click on your .cpp file in the soluition explorer, choose
"Properties", and find the "Precompiled header files" option - change it to
"not using pre-compiled headers".

-cd
Anil Gupte - 15 Aug 2007 07:11 GMT
Thanx for the response.  Since I am learning VC++ (I am familiar with
VB.Net), I would appreciate it if you can tell me what that file was for and
why do you think the author forgot to mention it?

Signature

Anil Gupte
www.keeninc.net
www.icinema.com

>> I have never been so embarassed! :-)  I have played with C++, and even
>> created a few simple programs, but decided to learn it properly.  So
[quoted text clipped - 30 lines]
>
> -cd
Bo Persson - 15 Aug 2007 11:23 GMT
:: Thanx for the response.  Since I am learning VC++ (I am familiar
:: with VB.Net), I would appreciate it if you can tell me what that
:: file was for and why do you think the author forgot to mention it?

I don't think the author forgot to mention this file. This is VC
specific.

When you create a new project, you get the Precompiled Header option
checked by default. The files generated by the project wizard will
also contains an #include "stdafx.h".

If you want to use your own code, uncheck the Precompiled Header and
check the Empty Project option instead. Then add any files you like.

Bo Persson

:: --
:: Anil Gupte
[quoted text clipped - 41 lines]
:::
::: -cd
Ben Voigt [C++ MVP] - 15 Aug 2007 14:08 GMT
> :: Thanx for the response.  Since I am learning VC++ (I am familiar
> :: with VB.Net), I would appreciate it if you can tell me what that
> :: file was for and why do you think the author forgot to mention it?
>
> I don't think the author forgot to mention this file. This is VC specific.

The name of the book the OP was using started with "Visual C++", so that
would seem to be a rather serious oversight.  Probably the new project
wizard has changed since the book was written, so it wasn't clear to the OP
that the "Empty Project" option needed to be checked.

> When you create a new project, you get the Precompiled Header option
> checked by default. The files generated by the project wizard will also
[quoted text clipped - 50 lines]
> :::
> ::: -cd
pvdg42 - 15 Aug 2007 20:19 GMT
> The name of the book the OP was using started with "Visual C++", so that
> would seem to be a rather serious oversight.  Probably the new project
> wizard has changed since the book was written, so it wasn't clear to the
> OP that the "Empty Project" option needed to be checked.

I'd like to see that book, as the oversight covers previous versions of
Visual Studio going back to VS 6. Our beginning C++ students are instructed
to *always* create empty Win32 console projects, then add a source code
file. We've used that procedure since VC 6 to avois the issue experienced by
the OP.
Possibly the OP missed the Empty Project step in the book?
Ben Voigt [C++ MVP] - 15 Aug 2007 20:25 GMT
>> The name of the book the OP was using started with "Visual C++", so that
>> would seem to be a rather serious oversight.  Probably the new project
[quoted text clipped - 7 lines]
> experienced by the OP.
> Possibly the OP missed the Empty Project step in the book?

IIRC, no precompiled headers was the default in prior versions of VC, you
had to request skeleton code.
PvdG42 - 15 Aug 2007 22:42 GMT
> IIRC, no precompiled headers was the default in prior versions of VC, you
> had to request skeleton code.
I have no installations of VS 2003 or earlier to help me remember, but we
instructed students to create empty projects in versions earlier than VS
2005 to avoid entanglements with some sort of code shell, I thought. Could
be my memory is bad, though :)
Anil Gupte - 19 Aug 2007 05:09 GMT
Sorry, I have been away.

Yes, you are absolutely right - Mea Culpa.  I overlooked the "Check the
Empty Project box" instruciton.  It was at the top of the page and I just
glazed....

:-)

Thanx all!

Signature

Anil Gupte
www.keeninc.net
www.icinema.com

>> The name of the book the OP was using started with "Visual C++", so that
>> would seem to be a rather serious oversight.  Probably the new project
[quoted text clipped - 7 lines]
> experienced by the OP.
> Possibly the OP missed the Empty Project step in the book?

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.