我采集到的数据在CString buf变量中,
我写进*.txt时,全排成一行了。
是不是必须将buf撤成每30个字符为一组,然后加上\r\n?
但怎样撤呢?

解决方案 »

  1.   

    CString temp;
    while(bug.GetLength()>30)
    {
        temp = bug.Left(30);
        write temp to file and add \r\n
        buf.delete(30,0);
    }
    temp = buf;
    write temp to file
    end
      

  2.   

    void CWriteReturnDlg::OnWrite() 
    {
    //实现每30个字符一个回车。
    CString str ="The production of this book required the efforts of many people, but two in particular deserve to be singled out for their diligent, sustained, and unselfish efforts. Sally Stickney, the book's principal editor, navigated me through that minefield called the English language and contributed greatly to the book's readability. Marc Young, whose talents as a technical editor are nothing short of amazing, was relentless in tracking down bugs, testing sample code, and verifying facts. Sally, Marc: This book is immeasurably better because of you. Thanks.";
    int iLen = str.GetLength() + 1;
    char *contents = new char[iLen];
    char *contentsReturn = new char[2 * iLen];
    strcpy(contents,str);

    for (int i = 0, j = 0; contents[i] != '\0'; i++) 
    {
    if (!(i%30))
    {
    contentsReturn[j++] = '\r';
    contentsReturn[j++] = '\n';
    }
    contentsReturn[j++] = contents[i];
    }
    contentsReturn[j] = '\0';

    MessageBox(contentsReturn); //将这里改为你写文件的操作就可以了
    delete []contents;
    delete []contentsReturn;
    }
      

  3.   

    两位的做法出现同一问题:
    保存的TXT文件,在找开时说文件太大不能打开。
    其实就几百个字节都会说文件太大,是什么原因?
      

  4.   

    http://eaoo.com/design/list.asp?classid=2&Nclassid=13