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 below code :
#include <iostream>
Try this:
#include "stdafx.h"
#include <iostream>
int _tmain(int argc, _TCHAR* argv[])
{
std::cout << "Hello World";
}
should be fine now
Related
I am using visual studio 2013 to build a C++ console application.This is my code which gives an error. I need to write to the console for every function in my application.
// RAT.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
int _tmain(int argc, _TCHAR* argv[])
{
std::cout << "Process started";
return 0;
}
It gives the following error,
Error:namespace "std" has no member "cout"
I dont understand why this basic "cout" gives a such error :(
Please help me I am totally confused....
You need to place #include <iostream> as your header.
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
cout << "hello world" << endl;
return 0;
}
The code is as above, very simple example, but I get many errors like:
variable "_CRTIMP_ALTERNATIVE" is not a type name Project2 d:\tools\VC\include\string.h 98
variable "errno_t" is not a type name Project2 d:\tools\VC\include\crtdbg.h 848
and so on...
Image is here:
http://postimg.org/image/adhcs4p39/
Your image looks like VS2015, but the _CRTIMP_ALTERNATIVE macro and errno_t type are not used or defined in the 2015 headers that I can find. They are in the VS2012 headers (both are in crtdefs.h). This looks like you are compiling against a mix of header files, with some from one compiler version and some from the other.
I uninstalled 2012 version. Works like a magic!
C2143: syntax error : missing ';' before '<'
I might be quite rusty in C++ since I sincerely don't know the reason of such errors.
The code is actually quite simple. (VS2003)
#include <vector>
class store
{
public:
vector<int>storage;
};
int _tmain(int argc, _TCHAR* argv[])
{
return 0;
}
Because you need to add std:: in front of vector:
std::vector<int>storage;
The vector class is inside the std namespace.
Or just add
using namespace std;
which is highly NOT recommended, especially for header files.
#include <cstdlib>
using namespace std;
/*
*
*/
int main(int argc, char** argv)
{
cout << "COME AT ME BRO!\n"
return 0;
}
It says cout is unable to resolve identifier
The C++ code assistance is setup properly, I'm just not sure whatelse it could possibly be.
You did not include <iostream> and thus the identifier std::cout is never declared or defined in your program.
You're including the wrong header file. It should be :
#include <iostream>
I got a strange compilation error when I followed the MSDN document to use CA2W to convert big5 strings to unicode strings in Visual Studio 2005.
This is the code I wrote:
#include <string>
#include <atldef.h>
#include <atlconv.h>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
string chineseInBig5 = "\xA4\xA4\xA4\xE5";
ATL::CA2W(chineseInBig5.c_str());
return 0;
}
The compilation error: error C3861: 'AtlThrowLastWin32': identifier not found
I don't know how this could happen. The document of AtlThrowLastWin32 shows that atldef.h is required, but I couldn't find the declaration of AtlThrowLastWin32 in atldef.h.
I finally solved this problem by adding 2 include headers:
#include <atlbase.h>
#include <atlstr.h>
I don't know why the MSDN document doesn't mention that.