c++でエラーがでる。error: use of undeclared identifier 'cin'
解決したいこと
macosでc++を始めました。基本的なコードを書いたらエラーが出てしまいました。
解決方法を教えてください。
発生している問題・エラー
Main.cpp:6:5: error: use of undeclared identifier 'cin'
cin>>n;
^
Main.cpp:7:5: error: use of undeclared identifier 'cout'; did you mean 'count'?
cout<<n<<endl;
^~~~
count
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/__algorithm/count.h:25:5: note: 'count' declared here
count(_InputIterator __first, _InputIterator __last, const _Tp& __value) {
^
Main.cpp:7:5: error: reference to overloaded function could not be resolved; did you mean to call it?
cout<<n<<endl;
^~~~
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/__algorithm/count.h:25:5: note: possible target for call
count(_InputIterator __first, _InputIterator __last, const _Tp& __value) {
^
Main.cpp:7:14: error: use of undeclared identifier 'endl'
cout<<n<<endl;
^
4 errors generated.
該当するソースコード
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
cout<<n<<endl;
}
補足
https://zenn.dev/minguu42/articles/20220722-how-to-use-gcc-on-mac
上記のブログの言うとおりにしたら、エラーコードが出なくなりました。
0 likes