C and C++

Moderators: None (Apply to moderate this forum)
Number of threads: 28629
Number of posts: 94611

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
visual C++ Posted by philshell on 24 Mar 2010 at 12:34 PM
I tried to program on Visual C++ and it says, did you forget #include<stdafx.h>. I tried using #include<iostream> and it is giving a warning and an error for cout<<" ";. Can somebody please write a short code for this compiler header. What are the other alternatives to make this program work?

Thanks

Shelley
Report
Re: visual C++ Posted by HK_MP5KPDW on 25 Mar 2010 at 12:53 PM
The cout error might be because you aren't taking the namespace issues into account. You need to make sure that in some way you tell the compiler that you are using the cout stream that's a part of the std namespace. There are 3 ways this is typically done:
#1

#include <iostream>

...

std::cout << ...

#2

#include <iostream>
using std::cout;
...

cout << ...

#3

#include <iostream>
using namespace std;

...

cout << ...

The first method is generally preferred by the more experienced coders and the last one used most often in smaller projects and by beginners.

As for the stdafx thing, what type of project are you creating - Win32 Application/Win32 Console Application/etc...? I'm personally of the opinion that dealing with pre-compiled headers is mostly a pain-in-the-$#@. Whenever I create a project, whatever type it is, I always select "empty project" from the wizard. Choosing other options always seems to force you to have that stdafx piece in there.
Report
Re: visual C++ Posted by philshell on 25 Mar 2010 at 8:29 PM
I found out by writing #include<stdafx.h> and sfter that #include<iostream> in that order the program works.

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

int main()
{
cout<<"Hello world! \n";
return0;
}

works fine.

If you have anymore variations please write!!!

Report
Re: visual C++ Posted by anthrax11 on 25 Mar 2010 at 9:19 PM
When using precompiled headers, StdAfx.h has to be included in all source files and as the first statement within every source file. Precompiled headers can be turned off in the project property pages, it just makes compilation a little slower if you have many source files and use many headers (such as the Windows SDK).



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.