C++ 如何停止 IntelliSense PCH 警告?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19215981/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 22:37:00  来源:igfitidea点击:

How do I stop an IntelliSense PCH Warning?

c++visual-studio-2010headerincludeintellisense

提问by NobleUplift

A few of my header files have no includes, so I receive this message in Visual Studio 2010:

我的一些头文件没有包含,所以我在 Visual Studio 2010 中收到了这条消息:

IntelliSense: PCH warning: cannot find a suitable header stop location.  An intellisense PCH file was not generated.

If I add a single header, for instance:

如果我添加单个标题,例如:

#include <iostream>

It disappears. How can I stop this error from showing without adding (potentially unused) include>

它消失了。如何在不添加(可能未使用)的情况下阻止此错误显示>

采纳答案by tatigo

When adding a .cpp file it inherits the PCH settings of the project. More detailed explanation of the problem here

添加 .cpp 文件时,它会继承项目的 PCH 设置。更详细的问题解释here

Solutions:

解决方案:

  1. Add #pragma onceat the start of the file.
  1. #pragma once在文件开头添加。

It will cause your source file to be included only once in a single compilation, therefore the compiler will be satisfied and won't require additional #include

它会导致你的源文件在一次编译中只包含一次,因此编译器会满意并且不需要额外的 #include

  1. Setting your project to not use precompiled headers
  2. Disable PCH usage for that one cpp file you've added, which will clear both IntelliSense and compiler warning/error.
  1. 将您的项目设置为不使用预编译头文件
  2. 为您添加的那个 cpp 文件禁用 PCH 使用,这将清除 IntelliSense 和编译器警告/错误。

Note! I'm including num 2, and 3 because some say it helped, but it only num 1 that did solve my case.

笔记!我包括 num 2 和 3,因为有人说它有帮助,但只有 num 1 确实解决了我的问题。

回答by Serid

I suppose the problem is that you have precompiled header in your project (by default "stdafx.h") and to correctly solve the problem you should add

我想问题是您的项目中有预编译的头文件(默认情况下为“stdafx.h”)并且要正确解决您应该添加的问题

#include "stdafx.h"

at start of your header/source file.

在头文件/源文件的开头。

回答by Natasha

Go to project's property and under C/C++ => Precompiled Headers, find the option "Precompiled header".

转到项目的属性并在C/C++ => Precompiled Headers 下,找到选项“Precompiled header”。

Change it to "Not Using Precompiled Headers".

将其更改为“不使用预编译头”。

enter image description here

在此处输入图片说明