Basic input and output in Online judge

Source: Internet
Author: User

First, the use of C language processing input and output

1. Enter:

In the C language input in the stdin pointer represents the standard input, scanf default reading is stdin point to the input, in ACM we may need to constantly test, it is best to redirect stdin to a file, so it is convenient to debug, use the following methods.

Freopen ("Iniflename", "R", stdin); The function, in turn, specifies the input file, operation mode, directed to the file pointer, so in the following reading, can be read according to SCANF.

The scanf function returns the number of successful reads and returns EOF=-1 if nothing is read. You can use char c = GetChar () when reading a string, and get a character;

Can be used when reading multiple characters, Char s[45]; Get (s); If you read by a space, you can use scanf.

2. Output:

c Use the printf function for output. The function uses the STDOUT pointer as the standard output and redirects the method:

Freopen ("outfile","w", stdout);

Second, C + + processing input and output

1. Enter:

Similar to the C language, C + + defines standard object CIN Reader standard input, cin >> a >> b; The >> operator actually returns a reference to an object, but in the while (CIN >> N), it is converted to the void* type, so it can be used for the judgement of the bool type. Methods for redirecting CIN:

Ifstream ifile ("infilename"*strmin_buf = Cin.rdbuf (Ifile.rdbuf ());

Returns a STREAMBUF pointer to the currently read buffer address.

2. Output:

C + + uses cout output, redirection method:

Ofstream outfile ("outfilename"*strmout_buf = Cout.rdbuf (Outfile.rdbuf ());

Returns a streambuf pointer to the buffer address of the current write.

Basic input and output in Online judge

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.