怎样将枚举类型数据存成文本文件?
我的程序是这样的:enum PicType{bottom, inside, outside, unengaged};class tempfile : public CObject
{
protected:
DECLARE_SERIAL(tempfile);
int a;
short b;
         long c;
         float d;
         double e;
         BOOL f;
CString str;
         PicType type; 
public:
tempfile();
virtual ~tempfile();
void Save(CFile *pFile);
void Serialize(CArchive &ar);
};tempfile::tempfile()
{
a = 10;
b = 20;
         c = 30;
         d = 40;
         e = 50;
         f = TRUE;
str = "the end!";
         type = unengaged;
}void tempfile::Save(CFile *pFile)
{
         CString cs;         cs.format("\t%???\r\n", a);
pFile->Write(cs, cs.GetLength());         cs.format("\t%???\r\n", b);
pFile->Write(cs, cs.GetLength());         cs.format("\t%???\r\n", c);
pFile->Write(cs, cs.GetLength());         cs.format("\t%???\r\n", d);
pFile->Write(cs, cs.GetLength());         cs.format("\t%???\r\n", e);
pFile->Write(cs, cs.GetLength());         cs.format("\t%???\r\n", f);
pFile->Write(cs, cs.GetLength());         cs.format("\t%???\r\n", str);
pFile->Write(cs, cs.GetLength());         cs.format("\t%???\r\n", type);
pFile->Write(cs, cs.GetLength());}程序中???应用什么来代替,比如d,s,f或者其他的,尤其是枚举类型应怎么处理?

解决方案 »

  1.   

    不知道。输出到终端用cout<<PicType[a]好象可以
      

  2.   

    像你这样枚举类型很少,用比较笨的方法:
    CString cs1;
    if (m_PicType == bottom)
    {
    cs1 = "bottom";
    }
    else if (m_PicType == inside)
    {
    cs1 = "inside";
    }
    else if (m_PicType == outside)
    {
    cs1 = "outside";
    }
    else
    {
    cs1 = "undefine";
    } cs.Format("\t%s\r\n", cs1);
    pFile->Write(cs, cs.GetLength());