File contents
2
3 2
1 4 1 1 0 11
4 1 1 1 8 11
2 5 0 0 0 11
4 1 0 0 0 11
5 5
2 4 1 0 1 13
4 4 0 1 12 13
1 4 1 1 0 13
3 5 1 1 7 13
One, format read
1. C language
FILE * f_in = fopen ("1.txt","R"); intK; intm, N; intdp[6]; FSCANF (f_in,"%d", &k); while(k--) {fscanf (f_in,"%d%d", &m, &N); for(inti =0; I <4; ++i) {fscanf (f_in,"%d %d%d%d%d%d", &dp[0], &dp[1], &dp[2], &dp[3], &dp[4], &dp[5]); } }
2. C + + >> input operators stop typing when they encounter whitespace characters, but leave whitespace characters in the buffer
Ifstream f_in ("1.txt"); intK; intm, N; intdp[6]; F_in>>K; while(k--) {f_in>> m >>N; for(inti =0; I <4; ++i) {f_in>> dp[0] >> dp[1] >> dp[2] >> dp[3] >> dp[4] >> dp[5]; cout<< dp[0] <<","<< dp[1] <<","<< dp[2] <<","<< dp[3] <<","<< dp[4] <<","<< dp[5] <<Endl; } }
Second, read a line
C++
Getline always reads newline characters, reads line breaks from input cache and discards newline characters
Ifstream f_in ("1.txt"); string str; while (Getline (f_in, str)) { << str << Endl; }
C language Fgets read and discard newline characters.
file* f_in = fopen ("1.txt""R"); Char str[1024x768]; while 1024x768 , f_in)) { << str; }
Format Read and read line