c++ - reading from file, gcount() is always 0 even after several file.get() -


i'm trying read file using file.get() seems stuck in first line. input file like:

1234,56 7891,01 ....... 

this 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 make sense of this.

get(char*, streamsize) gets stuck encounters newline delimiter. need use getline() advance next line.

also, second get() reads 2 characters stream (i.e read ",5" instead of ",56" first line.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -