代码中的 C++ 标准错误

c++ std error in code

本文关键字:标准 错误 C++ 代码      更新时间:2023-10-16

我刚开始 c++

这是一个基本主声明的代码,基于我找到的许多教程,还包含将 hello world 打印到控制台的代码

// TestApp.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"

int _tmain(int argc, _TCHAR* argv[])
{
    std::cout << "Hello World";
}

我正在使用VS 2012 Express,我不知道哪个编译器,但"cout"以红色下划线

错误如下:

错误

C2039 "cout":尼特是"std"的成员吗 LN 9 col 1 错误 C2065 : 未声明的标识符 ln 9 col 1 智能感知: 命名空间 "std" 没有成员 "cout" ln 9 col 7

我不明白为什么它会给出错误,有人可以启发我吗?

错误告诉您std::cout尚未在此翻译单元的任何地方声明。如果尚未声明某些内容,则无法使用该内容。 std::cout在C++标准库<iostream>标头中声明:

#include <iostream>

如果将来收到类似的错误,并且需要知道要包含哪个标头,请查找要使用的特定函数/类型的一些文档。例如,如果您查看 cppreference.com,它会指出"在标题<iostream>中定义"。

包含以下代码:

#include <iostream>

试试这个:

#include "stdafx.h"
#include <iostream>
int _tmain(int argc, _TCHAR* argv[])
{
    std::cout << "Hello World";
}

现在应该没事了