有一个txt文件,文件内容如下:
Table of Contents<>,3
EPS Spec<>,5
Introduction<>,5
Guidelines for Creating EPS Files<>,7
Required DSC Header Comments<>,7
Conditionally Required Comments<>,9
Recommended Comments<>,10
Illegal and Restricted Operators<>,10
Stacks and Dictionaries<>,10
Graphics State<>,11
Initializing Variables<>,11
Ensuring Portability<>,12
Miscellaneous Constraints<>,13
Guidelines for Importing EPS Files<>,13
Displaying an EPS File<>,13
Producing a Composite PostScript Language Program<>,14
File Types and Naming<>,22
Apple Macintosh File System<>,22
MS-DOS and PC-DOS File System<>,22
Other File Systems<>,22
Device-Specific Screen Preview<>,22
Apple Macintosh PICT Resource<>,23
Windows Metafile or TIFF<>,23
Device-Independent Screen Preview<>,24
Guidelines for EPSI Files<>,25
EPS Example<>,27
Appendix: Changes Since Earlier Versions<>,31
Index<>,33下面代码是读这个txt文件,按照每一行的tab个数确定一个level,填充该行到一个结构中,然后把所有行的结构放到一个vector之中去。最后把这个vector填充到tree ctrl之中。这部分代码搞不定了高分求达人搞定之

解决方案 »

  1.   

    读文件部分代码如下
    ///////////////////////////////////////////////////////////////
    struct SPAGENODE
    {
    int level;
    CString bookname;
    int pageno;
    };int ReadBook(vector<SPAGENODE> & m_aryBook)
    {
    TCHAR szFileName[MAX_PATH];
    FILE * fBookFile;
    if((fBookFile = fopen(szFileName, _T("r"))) != NULL)
    {
    int nestDepth = 0;
    int m_nNodeList = -1;
    CString m_strLine;

    TCHAR textline[4096];

    while(fgets(textline, 4096, fBookFile))
    {
    m_strLine = textline;
    m_strLine.Remove('\r');
    m_strLine.Remove('\n');
    int m_nTabCount = 0;//Tab
    int length = m_strLine.GetLength();

    if(length <= 0)
    continue;

    TCHAR * splitStr = _T("<>,");
    int i;// = m_strLine.Find(splitStr,0);
    const TCHAR * ppp1 = LPCTSTR(m_strLine);
    const TCHAR * ppp = strstr(ppp1, splitStr);

    if(ppp == NULL)
    i = -1;
    else
    i = ppp - ppp1;

    CString m_strText;//书签内容

    if(i == -1)
    m_strText = m_strLine;
    else
    m_strText = m_strLine.Left(i);

    m_strText.TrimLeft('\t');
    CString m_strPageNO = _T("1");

    if(i == -1)
    {
    }
    else
    {
    int first = i + strlen(splitStr);

    for(i = first; i < length; i++)
    {
    if(m_strLine[i] == ',')
    break;
    }

    if(i - first > 0)
    m_strPageNO = m_strLine.Mid(first, i - first);
    }

    while(m_strLine[m_nTabCount] == '\t')
    {
    m_nTabCount++;
    }

    //if(m_strText.GetLength() > 0)
    {
    //根目录
    //m_nNodeList++;
    int pageno = atoi(m_strPageNO);
    SPAGENODE m_nPageNode;
    m_nPageNode.bookname = m_strText;
    m_nPageNode.level = m_nTabCount;
    m_nPageNode.pageno = pageno;
    m_nPageNode.bookname.Replace(_T("\""), _T("&quot;"));
    m_nPageNode.bookname.Replace(_T("<"), _T("&lt;"));
    m_nPageNode.bookname.Replace(_T(">"), _T("&gt;"));
    m_aryBook.push_back(m_nPageNode);
    }
    }

    fclose(fBookFile);
    }

    return m_aryBook.size();
    }
      

  2.   

    这个好像是Adobe的EPS文件格式说明
      

  3.   

    你把大家都搞晕了:)对数组根据level进行排序,然后插入到树节点中呢
      

  4.   

    楼主本已达人了。struct SPAGENODE
    {
    int level;
    CString bookname;
    int pageno;
    };在CString 在中间,为何没有operator=,copy constructor,
    需要排序,怎么没有operator<(operator>)
    如果需要比较,怎么没有operator==?
      

  5.   

    呵呵,不会是读文件不对吧?呵呵,如果使用SDK FILE自己写。
      

  6.   

    vector已经填充好了,现在要根据这个vector按照txt文件中的格式向一个CTreeCtrl中填充item
      

  7.   

    ReadBook(m_aryBook);
    HTREEITEM hti = TVI_ROOT;
    int nLevel = -1;
    for(int i=0;i<m_aryBook.size();++i)
    {
    for(int j=0;j<=nLevel-m_aryBook[i].level;++j)
    hti=m_pTreeCtrl->GetParentItem(hti);
    hti=m_pTreeCtrl->InsertItem(m_aryBook[i].bookname,0,0,hti);
    nLevel = m_aryBook[i].level;
    }