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:chellohellohello.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;
}
原文地址:https://www.cnblogs.com/baby123/p/11306890.html