Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Why won't CString work??? 1

Status
Not open for further replies.

perplexd

Programmer
May 9, 2002
154
US
I'm probably missing something blatant as I'm new to C++. However, I can't seem to get CString to work. At the moment I'm just trying a test line, copied from VStudio help to try to get it to work. I'm using:

#include <string.h>

CString strName = _T(&quot;Name&quot;);

(I'm not entirely sure if it is needed, but I've also included string.h) Everytime I try to compile I just get the following errors:

Error C2065: 'CString': undeclared identifier
Error C2065: 'strName': undeclared identifier
Error C2146: syntax error: missing ';' before identifier 'strName'

As far as I can tell all these errors are generated by the fact that it is not recognising CString as a valid type. The only #include that I am aware of possibly needing is string.h so why is this happening?

The same errors are generated with:
CString strName;
CString strName = &quot;&quot;;
strName CString(_T(&quot;&quot;));

Many thanks
 
CString is an MFC class. You'll need an application that supports MFC to use it, and then you won't need to #include anything other than stdafx.h to get it. There is a standard library class that is just plain &quot;string&quot; that you can get without MFC. I prefer CString to string, but string can do most of the same stuff. To get string, just do this:

#include <string> // (there is no .h)
using std::string;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top