CString is not identified by Visual Studio 2005?

I have compiled with VS 2003

#include <afxwin.h> (at the top)

#include "stdafx.h"

#using <mscorlib.dll>

and declared in method like this

CString csUser, csPassword, csServer;

//===========================

The same syntax is giving this error in Visual Studio 2005!

error C2061: syntax error : identifier 'CString'

Spent four to six hours to resolve it,

However, I need this CString to work, but can not change it String* or any thing as the code runs a lot with CString.

Any help or clue, how to resolve it






Answer this question

CString is not identified by Visual Studio 2005?

  • ShmulikPrimes

    Just a random suggestion: are you compiling this file with /Yu If so then any code before the #include of <stdafx.h> will be ignored by the compiler.

    #include <atlstr.h>   // Bad as the #include is ignored
    #include "stdafx.h"
    #include <atlstr.h>   // Good



  • sticky27

    Oh! got it. Let me try this fix. Thanks a lot.

  • ricardo corbacho

    I've never understood why VC++ doesn't give a compiler warning in this case.  It's such an obvious (for the compiler) mistake, and happens all the time.
  • burberrybebe

    MSDN says CString's declaration is moved to afxstr.h. You can either include <afxstr.h> or <afx.h>
  • Peter Krochenski

    vbvan, thanks for the lead. It does not work giving the error like this.

    fatal error C1189: #error : afxstr.h can only be used in MFC projects. Use atlstr.h

    I tried atlstr.h, it gave many errors.

    For More info, I am trying to use this CString in a class (which is already coded and working fine with VS 2003) which is called by windows C++ forms.

    Thanks,



  • Joe.B

  • CString is not identified by Visual Studio 2005?