dimanche 20 octobre 2019

How to read .txt from file into 2D array

This is .txt file :

    00 00 00 00 01 02 04 05 00
    00 00 00 06 08 09 10 12 13
    00 00 00 17 19 14 15 18 07
    00 00 00 20 21 23 25 24 29
    22 26 28 35 34 31 33 38 39
    bb 30 31 34 32 36 03 11 16

i want to read this file into 2D int array. I cannot use vector .

i used getline and strtok but i got error message like that :

    error: ‘strtok’ was not declared in this scope
           point = strtok(str," ");

i included cstring . How can i do that ?.

string FileName;
fstream puzzle;
cout << "Please Enter the File Name : "  ;
cin >> FileName;
char str[100];
puzzle.open(FileName);
char *point;

i=0;
j=0;

while(!puzzle.eof()){
    puzzle.getline(str,100);
    point = strtok(str," ");
    while(point!=NULL){
        cout << point << " ";

        point = strtok(NULL , " ");
        j++;
    }
    i++;
    cout << endl;
}

Aucun commentaire:

Enregistrer un commentaire