0

我有一个包含如下内容的文本文件: 1|2|3|4|5|.......23|24|25

我需要阅读这个文件,标记值并将值输入二维数组。

for(i=0; i<size; i++) 
{
    for (j=0; j<size; j++)
    {   
        board[i][j] = *buffer;
        buffer++;
    }
}

我需要使用“|”标记值 作为 delim 并将值输入到二维数组中...请帮助。我知道以上不正确,请帮助。

4

2 回答 2

0
  • Read the data from file in a string.

  • Apply string tokenizer on your string and get the separate data.

    For tokenizing the string, take a look at Boost.Tokenizer. It's great. Boost generally has some very cool string tools.
    Once you get separate data you can store it in 2-D array.

于 2012-04-27T06:11:07.607 回答
0

You could read the whole file into a char * array. I'll assume that's what is in buffer and then use strtok to tokenize with "|".

http://www.cplusplus.com/reference/clibrary/cstring/strtok/

于 2012-04-27T06:12:15.627 回答