I am using visual C++ 2005(native C++)

I got the error
error C2065: 'CString' : undeclared identifier
for the following code,

#include <cstring>
using namespace std;

int main(){
	CString ab;
	ab="a";
}

what is the problem?

native c++ does not support CString -- that is a MFC c++ class. The cstring header file you included is the same as C's string.h, which is not at all like CString or c++ string.

>>what is the problem?
include <string> header file and use std::string object.

[edit]If you are using the Pro edition of that compiler I think you can create a console project that suports MFC non-visual classes such as CString. I know VC++ 6.0 does it, but not sure about VC++ 2005 Pro or newer compilers[/edit]

Since you are developing a Win32 Console Application, you don't get the boiler plate code that gets added for different project types.

Please include <atlstr.h> in your code after the pre-compiled headers.

Hope this resolves the issue.

Cheers,
Rajshree Dugar

Since you are developing a Win32 Console Application, you don't get the boiler plate code that gets added for different project types.

Please include <atlstr.h> in your code after the pre-compiled headers.

Hope this resolves the issue.

Caution:-
If you directly access the CString variable in a Win32 console application, you will get the address and not the content. In order to access the content of the variable you need to convert it to a native C++ type (for eg: std::string). My suggestion is to use std::string instead it is absolutely necessary to use CString. It is very much possible to use CString but not recommended due to conversion overhead. Pick your choice.

Cheers,
Rajshree Dugar

Goto Project -> Settings -> Use MFC in a Shared DLL
Then,
Please try to include #include <afx.h>

This article has been dead for over six months. Start a new discussion instead.