[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

compiler problem

Posted on 2006-05-13
3
Medium Priority
?
280 Views
Last Modified: 2011-09-20
Hey, I have been using java for a long time but I am currently learning C++ so.  When I try to compile this simple code in Microsoft.net edition

#include <iostream>
using namespace std;

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

i get a fatal error: "unexpected end of file while looking for precompiled header directive"
0
Comment
Question by:yattias
  • 2
3 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 200 total points
ID: 16676170
Try

#include "stdafx.h"
#include <iostream>
using namespace std;

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

and provide an empty "stdafx.h" in your current directory. VC++ used that file to create so called "precompiled headers" (which speed up the compilation process) and sets that file for the default. You could also turn that of in your project settings instead, go to "C++", choose "precompiled headers" and disable that.
0
 

Author Comment

by:yattias
ID: 16676232
thanks, it works now.  what is that "stdafx.h" and what does it do? how come the console opens and closes right away when I try to run it?
0
 
LVL 86

Expert Comment

by:jkr
ID: 16676262
>>what is that "stdafx.h" and what does it do?

As I wrote, VC++ uses it as its base file for precompiling headers. That has nothing to do with C++, but is a special thing of VisualStudio

>>how come the console opens and closes right away when I try to run it?

When your program terminates, the console will close. Just use

#include "stdafx.h"
#include <iostream>
using namespace std;

int main()
{
     char c;
     cout << "Hello" << endl;
     cin >> c;
     return 0;
}

(type a single char and hit "Enter" to terminate it)
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
Article by: evilrix
Looking for a way to avoid searching through large data sets for data that doesn't exist? A Bloom Filter might be what you need. This data structure is a probabilistic filter that allows you to avoid unnecessary searches when you know the data defin…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question