有这么一个文件Data.txt 内容如下:
'200 100 0 55 0 78 80 112'
想把它循环读出,中间空格不读。int temp;
CFile file("Data.txt",CFile::modeRead); 
DWORD dwFileLen;
dwFileLen = file.GetLength();
char *pbuf=new char[dwFileLen];
pbuf = new char[dwFileLen+1];
pbuf[dwFileLen] = 0;
file.Read(pbuf,dwFileLen); //已经把打开的文件放入到pbuf中如何把pbuf循环读出呢?比如int i=1时,数值temp等于200,比如int i=2时,数值temp等于100等等。

解决方案 »

  1.   

    strtok  这个函数可以哦。
      

  2.   

    msdn example:
    Example/* STRTOK.C: In this program, a loop uses strtok
     * to print all the tokens (separated by commas
     * or blanks) in the string named "string".
     */#include <string.h>
    #include <stdio.h>char string[] = "A string\tof ,,tokens\nand some  more tokens";
    char seps[]   = " ,\t\n";
    char *token;void main( void )
    {
       printf( "%s\n\nTokens:\n", string );
       /* Establish string and get the first token: */
       token = strtok( string, seps );
       while( token != NULL )
       {
          /* While there are tokens in "string" */
          printf( " %s\n", token );
          /* Get next token: */
          token = strtok( NULL, seps );
       }
    }
      

  3.   

    一次读入缓存中,然后利用CString::Tokenize()以空格为分隔符来拆分即可~
      

  4.   

    readline()读取一行,然后字符串Cstring分割就行
      

  5.   

    感觉LZ打的比方跟你问的问题不怎么对的上啊循环是怎么个意思?按照你打的比方来回答吧
    你可以下个二进制读取显示文件的软件(WinHex之类的),通过空格的二进制值去判断拆分数据,如果肯定空格分开的是数据的话,组出一个数据就OK了
      

  6.   

    一次性先读出来,用CStdioFile最方便,读到一个CString中去,然后用CString::Tokenize()来分割,不过VC6中的CString没有这个函数,你得用VS2008之类的才行。