C + + Read text file

Source: Internet
Author: User

#include <iostream> #include <fstream>using namespace Std;int main () {    int a,b=-100000,c;    cin>>c;    int i;    Ifstream infile ("F1.dat", ios::in);    for (i=0;i<c;i++)    {        infile>>a;        if (a>b)            b=a;    }    cout<< "max number:" <<b<<endl;    Infile.close ();    return 0;}
Description

In file F1.dat, n is provided (n is a very large number that is not required in the program) and a positive integer.

Please compile the program. The maximum value in the number of top N (n<n) in the output file.


The first 10 data in F1.dat, such as the following, are in the process of debugging a program. A self-built F1.dat file with a content of 10 integers.
52
69
21st
29
65
79
72
27
35
24


Input

The integer n, which represents the maximum value of the output, is the maximum number of top n in the F1.dat file

Output

The maximum value of the first n number in the F1.dat file. Because F1.dat is already given in the title, the maximum value depends on the file content.

The data given in the description section of the title: input n is 5 o'clock, output "Max number:69". Input n is 8 o'clock, output "Max number:79".

Sample Input5Sample OutputMax number:69

Copyright notice: This article blog original articles, blogs, without consent, may not be reproduced.

C + + Read text file

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.