今天想起電腦上的vs2015,發現好久沒用了,用了下,遇到了一個問題
由於不常用c++,還是覺得應該記錄下來,以免下次遇到,不知怎么處理
新建項目Hello
Hello.cpp
#include "stdafx.h" int main() { std::cout << "hello world!I'm C++." << std::endl; system("pause"); return 0; }
debug時出現
嚴重性 代碼 說明 項目 文件 行 禁止顯示狀態
錯誤 C2039 “cout”: 不是“std”的成員 Hello e:\c\hello\hello\hello.cpp 8
解決的方法:
包含命名空間std所在的頭文件iostream
#include <iostream>
下面的可以正常運行
#include "stdafx.h" #include <iostream> int main() { std::cout << "hello world!I'm C++." << std::endl; system("pause"); return 0; }
或
#include "stdafx.h" #include <iostream> using namespace std; int main() { cout << "hello world!I'm C++." << endl; system("pause"); return 0; }