0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

VisualStudio_stdafx.hでインクルードしている内容に対してIntellisenseがエラーを出す

Last updated at Posted at 2023-08-11

環境

Visual Studio Community 2022 (64ビット)

問題

コンパイルは通るのにIntellisenseがエラーと判断して赤線が消えない。

VisualStudio_stdafx_赤線.png
マウスオーバーすると以下のエラー内容が出る。

識別子"String"が定義されていません

エラーが出ているのはstdafx.hで定義しているはずの内容で、なぜかIntellisenseはそれらを「定義されていない」と判断している。

原因

stdafx.hをプロジェクトのルートディレクトリに置いており、この場所は自分の環境だとIntellisenseが効いていなかった。

プロジェクトのルート
  ├── src(自分が主にソースコードを置いている場所)
  ├── stdafx.cpp
  └── stdafx.h

解決

プロジェクト→「プロジェクト名」のプロパティ→構成を「すべての構成」にして構成プロパティ→C/C++→全般→追加のインクルードディレクトリに$(ProjectDir)を追加することで解決。
問題なくIntellisenseが効くようになった。
VisualStudio_stdafx_追加のインクルードディレクトリ.png

参考

MS Visual Studio 2022 intellisense stdafx.h problem - Microsoft Q&A
インテリセンスが効かない場合の対処方法(おいらの場合) - ir9Ex’s diary (hatenablog.jp)

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?