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.

'bits/stdc++.h' file not found と use of undeclared identifier 'cout'; の対処法

Posted at

はじめに

 以下のエラーが出ます。

c1.cpp:1:10: fatal error: 'bits/stdc++.h' file not found
#include <bits/stdc++.h>

 まず以下の記事にあるように、stdc++.h をダウンロードして配置します。

'bits/stdc++.h' file not foundの対処法 #C++ - Qiita

次に出たエラー

 cout が無いと言われます。

c1.cpp:5:3: error: use of undeclared identifier 'cout'; did you mean 'count'?
  cout << "Hello" << endl;
  ^~~~
  count

解決策

 #include <iostream> を書けばいいのですが、そもそも stdc++.h に入っているはずなので、書きたくありません。

 ダウンロードした stdc++.h から #include <iostream> を探すと、なにやら #if#endif の中に入っています。

 この行をどこでも良いから #if#endif の外に出します。必ず #include されるようにします。自分で使うだけだから、自分の環境だけ動けば良いです。

 これでコンパイルできるようになりました。

環境

ProductName:    Mac OS X
ProductVersion: 10.15.7
BuildVersion:   19H1713
Xcode 12.4
Build version 12D4e
Target: x86_64-apple-darwin19.6.0
LANG=ja_JP.UTF-8
zsh 5.7.1 (x86_64-apple-darwin19.0)
x64

参考

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?