You are not logged in. Please login at www.codechef.com to post your questions!

×

Fastest I/O C++?

3
2

Which is the most fast and efficient method for input output in c++ for large chunks of data? I know that the performance increases from cout cin to scanf printf,but I see people using much better methods here.If anyone could share one such method with a possible explanation to it,that would be great :D

asked 14 Oct '14, 23:50

h1ashdr%40gon's gravatar image

2★h1ashdr@gon
2912319
accept rate: 10%


link

answered 15 Oct '14, 10:55

topcoder_7's gravatar image

2★topcoder_7
2.9k3153
accept rate: 9%

Actually,cin and cout can be faster than scanf() and printf(). But it depends.If you are not using scanf() and printf() ,then at the start of main() use std::ios_base::sync_with_stdio(false);.This turns off the intermixing calls to scanf()/printf() with operations on cin/cout. Actually,by default cin/cout wastes time synchronizing with c library's stdio buffers. for more info,just have a look on the link : interacting with C

link

answered 15 Oct '14, 00:13

ansh1star033's gravatar image

3★ansh1star033
206129
accept rate: 9%

But people use stuff like register char c = getche_unlocked() something something etc..in C,which method is that?Is there any explanation?Can I use it in C++?

link

answered 15 Oct '14, 00:57

h1ashdr%40gon's gravatar image

2★h1ashdr@gon
2912319
accept rate: 10%

I would like you to go through the following links:

  1. http://discuss.codechef.com/questions/11364/fast-io-discussion
  2. http://discuss.codechef.com/questions/356/what-is-this-fast-io-code-than-printf-scanf-in-c
  3. http://discuss.codechef.com/questions/11811/fast-io-discussion
  4. http://discuss.codechef.com/questions/7394/help-on-fast-inputoutput

Also you can look at some of the submissions of this question. The top solutions of this question uses good fast i/o functions.
I personally use this code for fast input output.

link

answered 15 Oct '14, 01:29

roman28's gravatar image

4★roman28
1.6k71429
accept rate: 19%

edited 15 Oct '14, 01:31

It seems that, the difference by using std::ios_base::sync_with_stdio(false) is only observable if the input contains huge number of large integers, i.e. long or long long.

link

answered 02 Jun '17, 23:10

chdigvijay20's gravatar image

2★chdigvijay20
1
accept rate: 0%

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×1,912
×56
×22

question asked: 14 Oct '14, 23:50

question was seen: 21,018 times

last updated: 02 Jun '17, 23:10