vs2015 debug時出現 C2039“cout”: 不是“std”的成員


今天想起電腦上的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;
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM