375 27 5.000 5.000 122 444 333
375 27 5.000 5.000 122 444 333 375 27 5.000 5.000 122 444 333
375 27 5.000 5.000 122 444 333 375 27 5.000 5.000 122 444 333 375 27 5.000 5.000 122 444 333其中数值之间是用空格分割的,如何把其中的数值解析出来

解决方案 »

  1.   

    如果知道多少个数值,使用sscanf
    否则用CString分解每个空格前的数字,然后atoi
      

  2.   

    数值不定如何用CString分解每个空格前的数字啊
      

  3.   

    ///////////////////////////////////////////////////////////////
    // 函 数 名 : SplitStrToSA
    // 所属类名 : Global
    // 函数功能 : 将字符串拆分成字符串数组
    // 处理过程 : 
    // 备    注 : “@& abc@&de @&”按“@&”的拆分结果——》
    // (1)忽略空字符串:abc,de(拆分后数组长度为2)
    //              (2)不略空字符串:, abc,de ,(拆分后数组长度为4)
    // 作    者 : hesl
    // 时    间 : 2005年5月13日
    // 返 回 值 : void
    // 参数说明 : CString& inpStrSplit——[in]被拆分的字符串
    //    CStringArray& oupStrArray——[out]记录拆分结果
    //             CString strSeparator /*= _T(";")*/——[in]分隔符
    //    BOOL bIgnoreEmptyStr /*= TRUE*/——[in]是否忽略空字符串
    ///////////////////////////////////////////////////////////////
    void SplitStrToSA(CString& inpStrSplited, CStringArray& oupStrArray, CString strSeparator /*= _T(";")*/, BOOL bIgnoreEmptyStr /*= TRUE*/)
    {
    oupStrArray.RemoveAll();
    CString strSplited = inpStrSplited;

    // 依次拆分
    int nPos = strSplited.Find(strSeparator);
    CString strTemp;
    while(nPos != -1)
    {
    strTemp = strSplited.Left(nPos);
    if(bIgnoreEmptyStr)
    // 忽略空字符串
    {
    strTemp.TrimLeft();
    strTemp.TrimRight();
    if(!strTemp.IsEmpty())
    {
    oupStrArray.Add(strTemp);
    }
    }
    else
    // 不忽略空字符串
    {
    oupStrArray.Add(strTemp);
    }

    strSplited = strSplited.Mid(nPos + strSeparator.GetLength());
    nPos = strSplited.Find(strSeparator);
    }

    // 处理最后一截
    if(bIgnoreEmptyStr)
    // 忽略空字符串
    {
    strSplited.TrimLeft();
    strSplited.TrimRight();
    if(!strSplited.IsEmpty())
    {
    oupStrArray.Add(strSplited);
    }
    }
    else
    // 不忽略空字符串
    {
    oupStrArray.Add(strSplited);
    }
    }
      

  4.   

    CStringArray saSplitResult;
    SplitStrToSA(被拆分的字符串, saSplitResult, _T(" ")); 自己将字符串数组中的每个元素转换成数值吧
      

  5.   

    CString strSour = "375 27 5.000 5.000 122 444 333 375 27 5.000 5.000 122 444 333 375 27 5.000 5.000 122 444 333 375 27 5.000 5.000 122 444 333 375 27 5.000 5.000 122 444 333 375 27 5.000 5.000 122 444 333";CString strTmp;
    int n[1024];int pos = -1;// 这边自己做个循环,我就不做了
    if( pos = strSour.Find(' ') > 0 )
    {
        strTmp  = strSour.Left(pos);
        n[0]    = atoi(strTmp);
        strSour = strSour.Left( strSour.GetLength()-pos-1 );
    }
      

  6.   

    char tokenstring[] = "375 27 5.000 5.000 122 444 333";
        char seps[] = " ";
        char *token;
        
        token = strtok(tokenstring, seps);
        while( token != NULL )
        {
            TRACE("%s\n", token);  // 处理每个数字
            token = strtok( NULL, seps );
        }