例如有如下格式文件
/*----------------dat.dat---------------*/
04                            //此处第一行为文件数据行数
3,2,5,3,4,1
4,3,2,4
5,34,2,12,4
34,64,7,14,75
/*---------------end--------------------*/
如何讲文件中的4行中的每个数读入一个int i[4][n]的数组?
用CFile如何读入?
请给个简单的例子。我自己写了一个老是出毛病,弄了半天也没搞定
请大家帮忙!

解决方案 »

  1.   

    读取整行你没问题吧。然后就是拆分字符串
    use strtok function/* Compile options needed: none
    */ #include <string.h>
    #include <stdio.h>char *string = "a string,of ,,tokens";
    char *token;void main(void)
    {
            token = strtok(string," ,"); /*There are two delimiters here*/ 
            while (token != NULL){
                    printf("The token is:  %s\n", token);
                    token = strtok(NULL," ,");
            }

    The output of this program is as follows: 
    The token is: a
    The token is: string
    The token is: of
    The token is: tokens 最后是atoi了。
      

  2.   

    可以参阅C++Primer中的TextQuery类,很好用的
      

  3.   

    如何读一行呢?
    还有我没有c++primer,可以介绍一下用法吗?
    谢谢!