无法使用 Visual Studio 打开包含文件

Cannot open include file with Visual Studio(无法使用 Visual Studio 打开包含文件)

本文介绍了无法使用 Visual Studio 打开包含文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近从 Code::Blocks 转到 Visual Studio,并在Code::Blocks 可以只添加一个类,然后立即包含它.但是,每当我在 Visual Studio 中使用以下语句执行相同操作时:

I have recently gone from Code::Blocks to Visual Studio, and in Code::Blocks one could just add a class and then include it straight away. However, whenever I do the same in Visual Studio with the following statement:

#include "includedFile.h"

#include "include/includedFile.h"

它不起作用,而是我收到错误:

It doesn't work and instead I get the error:

无法打开包含文件:'includedFile.h';没有这样的文件或目录.

cannot open include file: 'includedFile.h'; no such file or directory.

是否有一些我必须勾选的框或设置?还是我必须手动将每个标头添加为依赖项?

Is there some box or setting that I have to tick? Or do I have to add each header as a dependency manually?

这是相关类的代码:

    #pragma once
    class Public
    {
        public:
            static const int SCREEN_WIDTH=1000;
            static const int SCREEN_HEIGHT=1250;
            Public(void);
            ~Public(void);
    };

Public.cpp:

Public.cpp:

    #include "Public.h"


    Public::Public(void)
    {
    }


    Public::~Public(void)
    {
    }

它是如何被收录的:

    #include "Public.h"

推荐答案

我在从 gcc 到 Visual Studio 进行 C 编程时遇到了同样的问题.确保您的包含文件确实在目录中——不只是显示在 VS 项目树中.对我来说,使用其他语言复制到项目树中的文件夹确实会将文件移入.使用 Visual Studio 2010,粘贴到头文件"中不会将 .h 文件放在那里.

I had this same issue going from e.g gcc to visual studio for C programming. Make sure your include file is actually in the directory -- not just shown in the VS project tree. For me in other languages copying into a folder in the project tree would indeed move the file in. With Visual Studio 2010, pasting into "Header Files" was NOT putting the .h file there.

请检查您的实际目录是否存在包含文件.将其放入项目/解决方案资源管理器中的头文件"文件夹是不够的.

Please check your actual directory for the presence of the include file. Putting it into the "header files" folder in project/solution explorer was not enough.

这篇关于无法使用 Visual Studio 打开包含文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:无法使用 Visual Studio 打开包含文件

基础教程推荐