Format Read and read line

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.