在代码中:
class CSingleView : public CView
{
protected: // create from serialization only
CSingleView();
DECLARE_DYNCREATE(CSingleView)// Attributes
public:
CSingleDoc* GetDocument();// Operations
public:// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CSingleView)
public:
virtual void OnDraw(CDC* pDC);  // overridden to draw this view
virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
protected:
virtual BOOL OnPreparePrinting(CPrintInfo* pInfo);
virtual void OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo);
virtual void OnEndPrinting(CDC* pDC, CPrintInfo* pInfo);
//}}AFX_VIRTUAL// Implementation
public:
string str; virtual ~CSingleView();
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endifprotected:// Generated message map functions
protected:
//{{AFX_MSG(CSingleView)
// NOTE - the ClassWizard will add and remove member functions here.
//    DO NOT EDIT what you see in these blocks of generated code !
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};红字部分是自己添加的一个变量声明,其余代码是mfc框架生成的。
加上代码就报错:
error C2146: syntax error : missing ';' before identifier 'str'
error C2501: 'string' : missing storage-class or type specifiers
error C2501: 'str' : missing storage-class or type specifiers本人刚在学习中,请赐教

解决方案 »

  1.   

    加一个:#include <string>
      

  2.   

    string 没有声明, 加个头文件
      

  3.   

    #include <string>
    using namespace std;
      

  4.   

    #include <string>
    using namespace std;
      

  5.   


    弱弱问一下string是什么东西?不是CString?- -
      

  6.   

    string和CString 是分别的两个字符串的类,CString是mfc的,而string是标准摸板库的。
      

  7.   

    原来酱紫深受mfc毒害的初学者飘过