AAABBBBCCDDDDDEEEEEEEEEEaaabbbxxx,
以A出现的次数是:3
B出现的次数是:4
.........
x出现的次数是:3   
 
对话框中 以这种格式输出txt,要怎样编程实现。

解决方案 »

  1.   

    for (i=1;i<VecTest.size();i++)
    {
    if(VecTest[i]==VecTest[i+1])
    {
    count++;
    CString  strtest;
    strtest.Format("%f",VecTest[i]);
    result1=strtest;
    }

    else if(VecTest[i]!=VecTest[i+1])
    {
    count=1;




    CString NUM;
    NUM.Format("%d",count);
    result = result +result1+ "出现的次数:"+"NUM"+ "\r\n";
    m_result=result;
    }
      

  2.   

    字符是存在一个vectest的数组容器中,上面的哪些地方有问题
      

  3.   


    for (i=1;i<VecTest.size();i++)
    {
    if(VecTest[i]==VecTest[i+1])
    {
    count++;
    CString strtest;
    strtest.Format("%f",VecTest[i]);
    result1=strtest;
    }else if(VecTest[i]!=VecTest[i+1])
    {
    count=1;
    } }//这里少了'}'CString NUM;
    NUM.Format("%d",count);
    result = result +result1+ "出现的次数:"+"NUM"+ "\r\n";
    m_result=result;
    }
    把前后文都贴出来吧。加下注释
      

  4.   

    读取的时候可以用迭代器:
    char firstChar,vChar;
    int  nCount=0;
    vector<char>::iterator it=vectest.begin();
    for (;it!=vectest.end();it++)
    {
          if (it==vectest.begin())
          {
             firstChar=*it;
             nCount++;
          } 
          else
          {
             vChar=*it;
             if (firstChar==vChar)
             {
                nCount++;
                firstChar=vChar;
             }
             else
             {
                CString strCount;
                strCount.Format(L"%d",nCount);
                MessageBox(strCount);
                nCount=1;
                firstChar=vChar;
              }
           }
    }