[c++] Visual c++ can't open include file 'iostream'

I am new to c++. I just started! I tried a code on visual c++ 2010 Express version but i got the following code error message.

------ Build started: Project: abc, Configuration: Debug Win32 ------
  ugo.cpp
c:\users\castle\documents\visual studio 2010\projects\abc\abc\ugo.cpp(3): fatal error C1083: Cannot open include file: 'iostream': No such file or directory
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

This is the code

// first.cpp -- displays a message


#include <iostream>   // a PREPROCESSOR directive

int main(void)        // function header
{             // start of a function body
  using namespace std;
  cout << "Come up and C++ me sometime.\n";  // message
  // start a new line
  cout << "Here is the total: 1000.00\n";
  cout << "Here we go!\n";
  return 0;
}

This question is related to c++

The answer is


Microsoft Visual Studio is funny when your using the installer you MUST checkbox a-lot of options to bypass the .netframework(somewhat) to make more c++ instead of c sharp applications, such as the clr options under dekstop development... in visual studio installer.... difference is c++ win32 console project or a c++ CLR console project. So whats the difference? Well i'm not going to list all of the files CLR includes but since most good c++ kernals are in linux... so CLR allows you to bypass a-lot of the windows .netframework b/c visual studio was really meant for you to make apps in C sharp.

Heres a C++ win32 console project!

#include "stdafx.h"
#include <iostream>
using namespace std;
int main( )
{
cout<<"Hello World"<<endl;
return 0;
}

Now heres a c++ CLR console project!

#include "stdafx.h"

using namespace System;

int main(array<System::String ^> ^args)
{
Console::WriteLine("Hello World");
return 0;
}

Both programs do the same thing .... CLR just looks more frameworked class overloading methodology so microsoft can great it's own vast library you should familiarize yourself w/ if so inclined. https://msdn.microsoft.com/en-us/library/2e6a4at9.aspx

other things you'll learn from debugging to add for error avoidance

#ifdef _MRC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif

Replace

#include <iostream.h>

with

using namespace std;

#include <iostream>

quick fix for small programs:

add: #include <cstdlib>


If you created an environment variable with the name IncludePath, try renaming it to something else.

This name will override $(IncludePath) inside project properties.


I had this exact same problem in VS 2015. It looks like as of VS 2010 and later you need to include #include "stdafx.h" in all your projects.

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

The above worked for me. The below did not:

#include <iostream>
using namespace std;

This also failed:

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

It is possible that your compiler and the resources installed around it were somehow incomplete. I recommend re-installing your compiler: it should work after that.


You are more than likely missing $(IncludePath) within Properties->VC++ Directories->Include Directories. Adding this should make iostream and others visible again. You probably deleted it by mistake while setting up your program.


I got this error when I created an 'Empty' console application in Visual Studio 2015. I re-created the application, leaving the 'Empty' box unchecked, it added all of the necessary libraries.


In my case, my VS2015 installed without select C++ package, and VS2017 is installed with C++ package. If I use VS2015 open C++ project will show this error, and using VS2017 will be no error.


    // first.cpp -- displays a message


#include <iostream>   // a PREPROCESSOR directive
using namesapce std;
int main()        // function header
{             // start of a function body
  ///using namespace std;
  cout << "Come up and C++ me sometime.\n";  // message
  // start a new line
  cout << "Here is the total: 1000.00\n";
  cout << "Here we go!\n";
  return 0;
}

Make sure you have Desktop Development with C++ installed. I was experiencing the same problem because I only had Universal Windows Platform Development installed.


Some things that you should check:

  • Check the include folder in your version of VS (in "C:\Program Files\Microsoft Visual Studio xx.x\VC\include" check for the file which you are including, iostream, make sure it's there).

  • Check your projects Include Directories in <Project Name> > Properties > Configuration Properties > VC++ Directories > Include Directories - (it should look like this: $(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSdkDir)include;$(FrameworkSDKDir)\include;)

  • Make sure that you selected the correct project for this code (File > New > Project > Visual C++ > Win32 Console Application)

  • Make sure that you don't have <iostream.h> anywhere in your code files, VS doesn't support that (in the same project, check your other code files, .cpp and .h files for <iostream.h> and remove it).

  • Make sure that you don't have more than one main() function in your project code files (in the same project, check your other code files, .cpp and .h files for the main() function and remove it or replace it with another name).

Some things you could try building with:

  • Exclude using namespace std; from your main() function and put it after the include directive.
  • Use std::cout without using namespace std;.

If your include directories are referenced correctly in the VC++ project property sheet -> Configuration Properties -> VC++ directories->Include directories.The path is referenced in the macro $(VC_IncludePath) In my VS 2015 this evaluates to : "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include"

using namespace std;
#include <iostream> 

That did it for me.