我有个字符串 CString info ="12\thello world\ttest\t" 我想通过sscanf(info,"%s\t%s\t%s\t",c1, c2, c3); c2只能获取到hello如何才能获取到 hello world啊,该如何写呢?

解决方案 »

  1.   

    sscanf(info,"%s\t%[^\t]%s\t",c1, c2, c3);
      

  2.   

    sscanf把空格当成一个字符串的结束。 你可以使用\t对CString进行Token..大概代码:int nPos = 0;
    CString strTmp = info.Token(_T("\t"), nPos);
    while(!strTmp.IsEmpty())
    {
        strTmp = info.Token(_T("\t"), nPos);    //循环到第二次就是你要的HelloWorld了。
    }
      

  3.   

            CString info ="12\thello world\ttest\t";
    CString sa[10];
    int i = 0; while(1){
    int pos = info.Trim().Find("\t");
    if(pos>=0){
    sa[i] = info.Left(pos).Trim();
    info = info.Mid(pos+1).Trim();
    } else {
    sa[i] = info.Trim();
    break;
    }
    i++;
    }
            CString c2 = sa[1];