I'm trying to read from a file using file.get()
but it seems to be stuck in the first line.
Input file is like:
1234,56
7891,01
.......
This is my code:
char* n1 = new char[5];
char* n2 = new char[3];
std::ifstream data("input_file");
while (i < 4) {
data.get(n1, 5);
printf("%ld\n", data.gcount());
data.get(n2, 3);
printf("%ld\n", data.gcount());
//read newline
data.get(&ch, 2);
printf("%ld\n", data.gcount());
printf("n1= %s, n2 = %s\n", n1, n2+1);
}
Output:
0
0
0
n1= 1234, n2 = 56
0
0
0
n1= 1234, n2 = 56
0
0
0
n1= 1234, n2 = 56
I'm not able to make any sense of this.