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

×

About Printf-Scanf and Cin-Cout

Can anyone please tell me exactly why printf-scanf works faster than cin-cout?

asked 11 Oct '14, 22:03

moudud99's gravatar image

4★moudud99
1861513
accept rate: 11%

(11 Oct '14, 23:03) nishant20024★

By default the i/o functions cin and cout are meant to synchronise with the library #include<stdio.h> . This makes them slow. You can change this by adding the following line below the int main () line of your function

std::ios_base::sync_with_stdio(false);

Note that after using this line you cannot use any instances of scanf and printf in your program. Else it'll give you a runtime error SIGSEGV. Also this makes cin and cout a tad bit faster than scanf and printf. You can check that on the problem INTEST.

link

answered 11 Oct '14, 22:21

pranjalranjan's gravatar image

4★pranjalranjan
2.0k21432
accept rate: 20%

1
(11 Oct '14, 22:50) pranjalranjan4★

It wil not increase speed of cout though..

http://codeforces.com/blog/entry/6251

(02 Aug '17, 11:17) kauts_kanu5★
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,914
×1,478
×169
×138
×46

question asked: 11 Oct '14, 22:03

question was seen: 3,078 times

last updated: 02 Aug '17, 15:33