How to read data from standard input (2) -- c++ language

Note: Bloggers will continue to update this document until the <unfinished to be continued> tag at the end of the article is cleared

Enter basic questions to consider

Algorithm competition topics generally have multiple test cases, and the data is sent to the program by means of redirection.
Then observe whether the output of the program is consistent with the expected results.
In most cases, these test cases will exist in the form of files. This pays attention to the following issues:

  1. There are multiple items of data in each line, and their delimiters are not completely determined, such as: one or more spaces.
  2. It may not be known how many items of data are on each row. Continues until the end of the bank.
  3. The total number of lines may not be known until the end of the file.
  4. The last line may not have a carriage return and line feed, directly encountering EOF (end of file marker)
  5. Under different operating systems, the way of wrapping may be different.
  6. When supplying a string, it may contain spaces.

Below we give some of the most common examples.

several lines, one integer per line

test data

3
5
-7
9

<To be continued>

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325942733&siteId=291194637