[英]c++ std error in code
I just started c++ 我刚开始C ++
here is the code for a basic main declaration and based on many tutorails I have found, also contains the code to print hello world to console 这是基本主声明的代码,基于我发现的许多tutorails,还包含用于打印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";
}
I am using VS 2012 Express, I dont know which compiler but the "cout" is underlined in red 我正在使用VS 2012 Express,我不知道使用哪个编译器,但是“ cout”用红色下划线
errors are as follows: 错误如下:
error C2039 'cout': is nit a member of 'std' ln 9 col 1 error C2065 : undeclared identifier ln 9 col 1 IntelliSense: namespace "std" has no member "cout" ln 9 col 7
错误C2039'cout':是'std'ln 9 col 1的成员。错误C2065:未声明的标识符ln 9 col 1 IntelliSense:名称空间“ std”没有成员“ cout” ln 9 col 7
I do not understand why it is giving an error, could someone please enlighten me? 我不明白为什么会出错,请有人启发我吗?
The error is telling you that std::cout
hasn't yet been declared anywhere in this translation unit. 该错误告诉您在此翻译单元中的任何地方都尚未声明
std::cout
。 You can't use something if it hasn't been declared. 如果尚未声明,则不能使用。
std::cout
is declared in the C++ standard library <iostream>
header: std::cout
在C ++标准库<iostream>
头文件中声明:
#include <iostream>
If you receive a similar error in the future and you need to know which header to include, look up some documentation for the particular function/type you want to use. 如果以后收到类似的错误,并且需要知道要包含哪个标头,请查找一些文档以了解要使用的特定功能/类型。 For example, if you look at cppreference.com , it states "Defined in header
<iostream>
". 例如,如果您查看cppreference.com ,它将显示“在标头
<iostream>
定义”。
包括以下代码:
#include <iostream>
Try this: 尝试这个:
#include "stdafx.h"
#include <iostream>
int _tmain(int argc, _TCHAR* argv[])
{
std::cout << "Hello World";
}
should be fine now 现在应该很好
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.