33
votes

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;
}
13
This has to be an installation problem of some kind. - Ernest Friedman-Hill
FYI, you should avoid using tabs in your code. They are very difficult to deal with when formatting on Q&A sites like this. Use spaces instead. - Code-Apprentice
I assume your include path includes the VC include directory (under program files). However, when installing VC did you select the native files? - Dai
Hi david, this is what i have in my include path : Program files (x86) > Microsoft Visual Studio 10.0 > VC > include > srv.h - jamesbond
@ David. How do i select the native file when installing VC? - jamesbond

13 Answers

18
votes

Replace

#include <iostream.h>

with

using namespace std;

#include <iostream>
10
votes

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;.
3
votes

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"
2
votes

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.

1
votes

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.

1
votes

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.

1
votes

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.

1
votes

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
1
votes

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

0
votes

quick fix for small programs:

add: #include <cstdlib>

0
votes

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.

0
votes

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

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

-1
votes
    // 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;
}