4 Replies - 2509 Views - Last Post: 30 May 2012 - 12:11 PM Rate Topic: -----

#1 crazy_person  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 18
  • Joined: 27-May 12

Problem compiling in Visual Studio: "error cout: undeclared identi

Posted 30 May 2012 - 11:12 AM

Hey so I am currently trying to build my programs using visual studio rather than code blocks but I am having trouble compiling.

#include <iostream>
#include <cstdlib>


using namespace std;

int main()
{
	cout << "HELLO WORLD!";
	return 0;
}



ERROR: C4627: '#include <iostream>': skipped when looking for precompiled header use

Why would I get that error? Why is iostream getting skipped?

Thanks!

Is This A Good Question/Topic? 0
  • +

Replies To: Problem compiling in Visual Studio: "error cout: undeclared identi

#2 crazy_person  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 18
  • Joined: 27-May 12

Re: Problem compiling in Visual Studio: "error cout: undeclared identi

Posted 30 May 2012 - 11:22 AM

I actually was able to compile it. I guess when I created a new project, the default automatically creates precompiled headers. I am sort of new to programming so anyone feel free to explain what a precompiled header does and why it lead me to problems. Thanks again!
Was This Post Helpful? 0
  • +
  • -

#3 Oler1s  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1395
  • View blog
  • Posts: 3,884
  • Joined: 04-June 09

Re: Problem compiling in Visual Studio: "error cout: undeclared identi

Posted 30 May 2012 - 11:50 AM

Precompiled header = a bunch of code precompiled to save time. When you have a large project with many files, the compilation time is significant (minutes or hours).

As a beginner, you should definitely not use precompiled headers.
Was This Post Helpful? 1
  • +
  • -

#4 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3162
  • View blog
  • Posts: 9,548
  • Joined: 05-May 12

Re: Problem compiling in Visual Studio: "error cout: undeclared identi

Posted 30 May 2012 - 11:54 AM

When you created a new project with precompiled headers VS should have generated a main program file for you with:
#include "stdafx.h"



I'm assuming that when you wrote/pasted in your code, you killed that line.

When MSVC compiles with precompiled headers on, it looks for a particular file to be included before all other headers. The default is file it looks for "stdafx.h", but this can be overridden. It uses this file as the container for all files which should be precompiled.

The value of precompiled headers is that it saves time. Let's say you have 10 .cpp files, all of which include iostream and cstdlib. Without precompiled headers, the compiler would have to read and parse the two files 10 times. Do a quick peek in those files and see how big they are, and any other files they may include. This slows down compile time dramatically, but isn't as painful as it used to be now that we have fast SSDs and HDs, but the time still adds up if you are in the middle of 'build-run-debug-fix' cycle. By using a precompiled header, the compiler only needs to read and parse those two files once and the parsing information is shared among all the files that use the precompiled header.

For more information, the wikipedia article is pretty digestable: http://en.wikipedia....compiled_header
Was This Post Helpful? 1
  • +
  • -

#5 crazy_person  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 18
  • Joined: 27-May 12

Re: Problem compiling in Visual Studio: "error cout: undeclared identi

Posted 30 May 2012 - 12:11 PM

Thanks a ton for replies! Definitely learned something that will be helpful in the future!

:)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1