I just started 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
// 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
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
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. You can't use something if it hasn't been declared. std::cout
is declared in the C++ standard library <iostream>
header:
#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>
".
包括以下代码:
#include <iostream>
Try this:
#include "stdafx.h"
#include <iostream>
int _tmain(int argc, _TCHAR* argv[])
{
std::cout << "Hello World";
}
should be fine now
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.