0

I have a kisiler.txt file like this.

102,Mustafa,E,2,54,0,0,1
103,Seher,K,2,65,0,1,0
104,Ali,E,1,88,0,1,0
105,Ahmet,E,3,12,1,0,0
106,Osman,E,5,2,0,0,0
107,Remziye,K,3,63,0,0,1
108,Ayse,K,1,10,0,0,0

I want to print data without commas from txt to two dimensional matrix. Like this

101 Tarkan  E 1 22 1 1 0
102 Mustafa E 2 54 0 0 1
........................
........................

How can i do this in c++ ?

#include <iostream>
#include <fstream>
#include <cstring>


/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;


void ReadFileFunc(){
    ifstream readFileFunc("kisiler.txt"); 
    // ...
    ReadFileFunc.close();
}

int main(int argc, char** argv) {
    
    ReadFileFunc();
    return 0;
} 
  • Have a look at `std::getline()` with special focus on the last argument which is `'\n'` by default but may be e.g. a `','` as well. I would consider to use nested loops - the outer to read the lines and the inner to read the columns in every line. – Scheff's Cat Dec 07 '20 at 12:46
  • 1
    why "no use vector"? Note that the use of a `std::vector` is not essential for the answer in the dupe. You can do similar with a different container – 463035818_is_not_an_ai Dec 07 '20 at 13:05

0 Answers0