We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,278 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion
Page 3 of Article: C++ advice (scanf/printf)
Always use scanf() and printf(). They are much, much faster than cin and cout. Also use stl algorithms, like sort, reverse and find, especialy if they are member functions of a container class you use.

wow this is a heated debate eh?

xxxxxxlolthis
Newbie Poster
1 post since Jun 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

I wouldn't call it a debate at all, more like some know-it-all being pwned by someone who actually knew what she was talking about. By the way, this thread is 6 years old...

deceptikon
Challenge Accepted
Administrator
3,452 posts since Jan 2012
Reputation Points: 822
Solved Threads: 473
Skill Endorsements: 57

This is what I got when I ran Narue's program on my netbook:
Operating System: Windows 7 Utimate
Processor: Inter atom N455 1.67 GHz
Memory: 2 GB

Printf: 289.978 s
cout: 23.950 s

cossay
Junior Poster
139 posts since Nov 2010
Reputation Points: 17
Solved Threads: 24
Skill Endorsements: 0

On my laptop:
cout: 0.89
printf: 67.89

Operating System: Windows 7 Ultimate 64-bit (6.1, Build 7601) Service Pack 1 (7601.win7sp1_gdr.120330-1504)
Processor: Intel(R) Core(TM) i3 CPU       M 330  @ 2.13GHz (4 CPUs), ~2.1GHz
Memory: 4096MB RAM

I'll try on my PC, to see if there's any difference between them.

Lucaci Andrew
Practically a Master Poster
649 posts since Jan 2012
Reputation Points: 91
Solved Threads: 91
Skill Endorsements: 12

Although this post is old. I still have some comment.
Brahle's idea applies well in programming contests such as ACM ICPC or Codeforces.
They judge the program based on the accuracy of output, not programming style.
And the judger redirects the input and output to files so that the actual input and output
are not the actual screen and keyboard but the files. And scanf and printf act a lot faster in this situation. (I don't know why)

I don't know about actual applications in real world, is scanf or cin better, but I've been in a lot of contests and thats where scanf and printf are unbelievably faster.

hackinghorn
Newbie Poster
1 post since Aug 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

I've actually learned how to properly clock loops!

neithan
Junior Poster in Training
92 posts since Oct 2009
Reputation Points: 12
Solved Threads: 3
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0721 seconds using 2.93MB