• Skip to main content
  • Skip to secondary menu
  • Skip to primary sidebar
  • Skip to footer

Mr.CodeHunter

Programming and Code Solutions

  • Home
  • C++
  • About Us
  • Contact Us
  • Privacy Policy

c++ cannot open source file [SOLVED]

May 30, 2021 by Admin 10 Comments

In c++ project when you have included header file, but inside project we are not able to access that header file then generally we get error for cannot open source file. For fixing this error check that included file is available in project include path or not.

cannot open source file visual studio C++

Solution-1 : Check your Visual Studio Project settings under C++, Check Include directories and make sure Your_filename.h is pointing to correct path. After adding proper include directories it will resolve cannot open source file visual studio error.

visual studio additional include directory
include directories to your header file

You can right click to header file and open from visual studio. If file is pointing properly it will open.

open c++ header file
Right click and try to open header file

If your include file is not properly pointing or you have not added inside your included directory then you will not able to open from visual studio.

error while opening header file
if file is not included in project then give this error

Solution-2 : Another solution, If your header file is at different folder/location then you can include file path directly in header file. Here you can use relative path or you can provide full path of header file.

Include based on your project folder structure and requirement.

#include "../FolderName/filename.h"
OR
#include "./FolderName/filename.h"
OR
#include "FullPath/filename.h"

c++ cannot open source file iostream

Solution-1: iostream file opening error normally comes when we are missing $(IncludePath) inside Properties->VC++ Directories->Include Directories. And you have by mistake removed Include path.

Solution-2: Other possible reason is that during installing Visual studio you did not selected c++ packages.

Solution-3: You can check by including stdafx.h in starting (only for Visual studio projects)

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

Solution-4: Sometimes these type of error comes when multiple Visual Studio versions are install in single PC. You can check Projects and Solutions –> VC++ Directories, are properly added for your project and pointing to correct version location.

For Visual Studio Code:

c++ cannot open source file iostream in visual studio code can also occurs when proper paths are not added inside visual studio code c_cpp_properties.json file.

Mode details:

https://code.visualstudio.com/docs/cpp/config-msvc#_prerequisites

cannot open source file “string”

Try below steps to resolve error.

1) Open VC++ Directories option inside Configuration Properties of visual studio
2) Her all directories value (e.g. Executable directories) will be available, just you need to select drop-down and click edit
3) Remove selection of Inherit from parent
4) Now just click OK and you will see no changes inside Edit box.
5) You need to repeat this thing for all directories, At the end executable directories will be set to $(ExecutablePath) and Include directories will be set to $(IncludePath), similar way to all directories
6)Now click apply and then OK

Conclusion for cannot open source file c++

We have provided solutions for multiple errors for can not open source file c++, If you try given solution hopefully you will able to resolve error. But if still you are getting error you can add your comment and code. We will try to resolve and find solution for you. Happy coding ๐Ÿ™‚

Top 10 C++ IDE – you must try once

Filed Under: All C++, C++

Reader Interactions

Comments

  1. Mark Edwards says

    December 1, 2021 at 1:18 pm

    Hi there from ‘down under’. I’ve just installed VS2022.
    However, I am getting error E1696: ‘cannot open source file “string.h” , ‘stdlib.h’ etc
    FYI I have been using Vs2019 and C# without probs.
    I also have visual studio code installed.
    Do I have to uninstall it/them?

    In my Wondows10 Environment Variables I have ‘VISUAL_STUDIO_REPOS’ defined where my projects are stored. Is there something else needing adding/deleting?

    Ta

    Reply
    • Admin says

      December 6, 2021 at 3:50 pm

      Hello Mark,
      Ok so what i understood, it is working proper with VS2019 but giving issue with VS2022. So then you need to make sure that You have installed Visual studio proper and Also check Windows SDK update require or not for new Version. Check this article points it might be helpful in your case: https://mrcodehunter.com/cannot-open-source-file-errno-h/
      Please check if latest Windows 10 SDK is required for same or not.
      No ideally not require to uninstall visual studio code. As you are running code in Visual Studio 2022.
      Also make sure you install Visual C++ during installation.
      Also once check given MSDN URL: https://social.msdn.microsoft.com/Forums/en-US/6ea597fe-fda5-464f-bcb7-a9b88bc7bf83/please-help-how-to-fix-error-e1696-file-source-cannot-be-opened-quotiostreamquot?forum=visualstudiogeneral

      Reply
  2. madhvan tyagi says

    December 22, 2021 at 4:25 pm

    i have just downloaded the open cv and trying to use it’s header files ,it showing me error in the top 2 header files , i tried the way you mentioned above but it sill not working , please sir help me if you can . i included the header file folder in additional include directories but i also have project include directories folder there

    #include
    #include
    #include
    #include

    using namespace cv;
    using namespace std;

    int main()
    {
    string path = “Resources/test.png”;
    Mat img = imread(path);
    imshow(“Image”, img);
    waitKey(0);
    return 0;

    }

    Reply
    • Admin says

      January 15, 2022 at 5:49 am

      Can you give more details for error ? Try everything and try to find that file is available in which location. Might be it will be in OpenCV folder. Generally by setting Include directory path it should be resolved. Did you check anything is missing for OpenCV configuration setup ?

      Reply
  3. Stepan says

    January 29, 2022 at 9:15 am

    #include
    #include
    #include
    #include
    #include “GenerateArray.h”-
    #include “ArrayOutput.h”- this 3 is doesnt work
    #include “SortArray.h”-
    int main()
    {
    int size = 40;
    int* arr = new int[size];
    int s = 0;
    do
    {
    printf(“1) Generate an array\n”);
    printf(“2) Display the array on the screen\n”);
    printf(“3) Sort array\n”);
    printf(“4) Display the sorted array\n”);
    printf(“5) Press zero to exit\n\n”);
    scanf_s(“%d”, &s);
    switch (s)
    {
    case 1:
    GenerateArray(size, arr);
    system(“CLS”);
    break;
    case 2:
    system(“CLS”);
    ArrayOutput(size, arr);
    printf(“\n”);
    break;
    case 3:
    SortArray(size, arr);
    system(“CLS”);
    break;
    case 4:
    system(“CLS”);
    ArrayOutput(size, arr);
    printf(“\n”);
    break;
    }
    } while (s > 0);
    }

    Reply
    • Admin says

      January 30, 2022 at 5:54 am

      Hello Stepan,
      Can you check:
      1) ArrayOutput.h file is available in current directory? check path of file
      2) Try to right click and open file, If it does not found you will get popup in visual studio that fine not found
      3) Try to give full path of file like D:/Data/…etc/ArrayOutput.h

      Reply
  4. gyeoulkis says

    April 3, 2022 at 6:24 am

    #include
    #include // this line is error, cannot open source file studio.h
    #include

    void draw() {
    glClear(GL_COLOR_BUFFER_BIT);
    glLoadIdentity();
    glOrtho(0, 4, 0, 4, -1, 1);
    glBegin(GL_POLYGON);
    glVertex2i(1, 1);
    glVertex2i(3, 1);
    glVertex2i(3, 3);
    glVertex2i(1, 3);
    glEnd();
    glFlush();
    }

    int main(int argc, char** argv) {
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA);
    glutCreateWindow(“whitesquare”);
    glutDisplayFunc(draw);
    glutMainLoop();
    }

    Reply
    • Admin says

      April 24, 2022 at 9:59 am

      studio.h is external library ? If yes then you need to add in your Project property for additional dependency library.

      Reply
  5. shahzaib says

    April 13, 2022 at 5:13 pm

    #include
    using namespace std;
    int main()
    {
    int rows = 0;
    int Maxdigit = 9;
    cout <> rows;
    while (rows % 2 == 0 || rows < 5)
    {
    cout << "Invalid Input. The entered number should be odd and greater than 5";
    cout << endl;
    cout <> rows;
    }
    if (rows != 7)
    {
    for (int i = 1; i <= rows; i = i + 2)
    {
    cout << " ";
    }
    cout << "1";
    for (int i = 1; i <= rows; i = i + 2)
    {
    cout << " ";
    }
    cout << endl;
    for (int i = 3; i <= rows; i = i + 2)
    {
    cout << " ";
    }
    for (int j = 3; j <= Maxdigit – 2; j = j + 2)
    {
    cout << j;
    if (j == 7)
    {
    cout << endl;
    cout <= 1; i = i – 2)
    {
    cout << i;
    if (i == 1)
    {
    cout << endl;
    cout << " ";
    for (int j = i + 2; j <= 9; j = j + 2)
    {
    cout << j;
    int count = count + 1;
    if (count == rows)
    {
    for (int i = j + 2; j <= 9; j++)
    {
    for (int k = j; k <= j; k = k + 2)
    {
    cout << k;
    }
    cout << endl;
    }
    }
    if (j == 7)
    {
    cout << endl;
    cout << " ";
    }
    }
    }
    }
    cout << " " << endl;
    }
    }
    for (int k = 1; k <= rows; k = k + 2)
    {
    cout << " ";
    }
    }
    if (rows == 7)
    {
    for (int i = 1; i <= rows; i = i + 2)
    {
    cout << " ";
    }
    cout << "1";
    for (int i = 1; i <= rows; i = i + 2)
    {
    cout << " ";
    }
    cout << endl;
    for (int i = 3; i <= rows; i = i + 2)
    {
    cout << " ";
    }
    for (int j = 3; j <= Maxdigit – 2; j = j + 2)
    {
    cout << j;
    if (j == 7)
    {
    cout << endl;
    cout <= 1; i = i – 2)
    {
    cout << i;
    if (i == 1)
    {
    cout << endl;
    cout << " ";
    for (int j = i + 2; j <= 9; j = j + 2)
    {
    cout << j;
    }
    for (int j = 1; j <= 5; j = j + 2)
    {
    cout << j;
    }
    cout << endl;
    cout << " ";
    for (int i = Maxdigit – 2; i <= 9; i = i + 2)
    {
    cout <= 3; j = j – 2)
    {
    cout << j;
    }
    cout << endl;
    cout << " ";
    for (int i = 5; i <= 9; i = i + 2)
    {
    cout << i;
    }
    cout << endl;
    cout << " 1";
    }
    }
    }
    }
    }
    system("pause");
    return 0;
    }

    Reply
    • Admin says

      April 24, 2022 at 10:00 am

      Can you tell me if you are getting any issue ? did not understood your comment. You just posted code.

      Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

Search here

Social Media

  • Facebook
  • YouTube

SEE MORE

Fibonacci sequence c++

Fibonacci Sequence c++ is a number sequence which created by sum of previous two numbers. First two number of series are 0 and 1. And then using these two number Fibonacci series is create like 0, 1, (0+1)=1, (1+1)=2, (2+1)=3, (2+3)=5 …etc Displaying Fibonacci Series in C++ ( without recursion) Output: From given output we […]

map c++

C++ Map [Learn by Example]

C++ map is part of Standard Template Library (STL). It is type of Associative container. Map in c++ is used to store unique key and it’s value in data structure. But if you want to store non-unique key value then you can use Multi Map in c++. Let us first understand in detail what is […]

how to copy paste in turbo c++ ?

There are many different C++ IDE are available but still many students are using Turbo c++ for learning c/c++ programming languages. During using Turbo c++ if you are beginner you will be confuse for how to copy and paste in turbo c++ or if you have already copy some content and you want to paste […]

C++

return 0 c++

There are two different scenario return statement is used inside c++ programming. We can use return 0 c++ inside main() function or other user defined functions also. But both have different meanings. return 0 c++ used inside Main function return 0 c++ used inside other user defined function What is meaning of return 0 and […]

C++

c++ expected a declaration [ SOLVED]

When any function or statement is not in scope or we have used wrong syntax then possibly you will get error for c++ expected a declaration in your code. Main reasons for errors are: Incorrect use/declaration inside namespace Statements are added out of scope Required statement need to add inside main/function Solution-1 | Expected a […]

C++

c++ cannot open source file “errno.h” [SOLVED]

Normally you will face c++ cannot open source file “errno.h” in MS Visual Studio c++ projects. These are some solutions to remove opening errors for “errno.h” file. I got the errors to go away by installing the Windows Universal CRT SDK component, which adds support for legacy Windows SDKs. You can install this using the […]

Footer

DISCLAIMER

The information contained on https://www.mrcodehunter.com is for general information purposes only. We assumes no responsibility for errors or omissions in the contents on the Service.

SITEMAP XML

Sitemap

Recent

  • Fibonacci sequence c++
  • C++ Map [Learn by Example]
  • how to copy paste in turbo c++ ?
  • return 0 c++
  • c++ expected a declaration [ SOLVED]

Search

Copyright © 2025 ยท Mr Code Hunter