Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-4041-8081-

iostream vs. stdio

Name: Anonymous 2007-11-22 14:09

so, I've got EXPERT PROGRAMMERS telling me to use printf instead of cout in c++, ok but why? what is the difference (in b4 stream)

Name: Anonymous 2007-11-22 14:16

>>1
C++ is a dirty hack.

Name: Anonymous 2007-11-22 14:19

ask them not us

Name: Anonymous 2007-11-22 14:21

>>3
but they are total fags...

Name: Anonymous 2007-11-22 14:25

>>1
they are not EXPERT PROGRAMMERS.
They would tell you not to use C++ at all if they where.

Name: Anonymous 2007-11-22 14:29

>>1
BLOATED EXECUTABLES

when you use any of the c++ i/o you're including statically alot of code, so your exe is HUEG

Name: Anonymous 2007-11-22 14:46

SEPPLES ITT

Name: Anonymous 2007-11-22 14:50

I was just thinking about iostreams yesterday. What the fuck? Why did they ever think
cout << "Yo" << " I'm " << 6 " fags!" << endl;
was a good idea? Not only does it look like bit shifts, it's longer and harder to read than the alternative would have been.

Name: Anonymous 2007-11-22 15:41

>>8
They probably did it to show off how C++ could overload operators and use objects. OMG NEW FEATURE LETS USE IT!!!111

>>6
You can link dynamically too, but it's still a very roundabout way of doing it (IIRC cout eventually calls through printf or something)

Name: Anonymous 2007-11-22 17:19

>>6
Yeah, that must be the reason.

:facepalm:

Name: Anonymous 2007-11-22 18:51

>>10
die

Name: Anonymous 2007-11-22 19:03

cout is an ugly hack.

printf is a very, very capable and universal way of printing data.

Basically, you're a dumb nigger so just use printf like we said.

Name: Anonymous 2007-11-22 19:08

>>6
solid numbers or gtfo.

Name: Anonymous 2007-11-22 20:33

>>13
/* hello.c */
#include <stdio.h>
main() {
 printf("Hello world!");
}

633 bytes

// hello.cpp
#include <iostream>
using namespace std;
main() {
 cout << "Hello world!";
}

2560 bytes

Obtained with maximum optimization and dynamic linking enabled.

Another program I wrote (the details don't matter, the important thing is that it writes to standard output A LOT) -- again, maximum opts and dynlink:

All stdio: 12KB
All iostream: 40KB

Name: Anonymous 2007-11-22 20:34

>>14
but which is faster?

Name: Anonymous 2007-11-22 20:36

>>15
i'd imagine stdio to be, but not by a whole lot

Name: Anonymous 2007-11-22 20:43

>>16
I actually haven't measured it, but I imagine cout is faster, or rather, has the potential to be faster. because printf interprets the format string, the cout stuff is determined at compile time.

Ok, yes, it's not a huge overhead. I'm a moron, forget it.

Name: Anonymous 2007-11-22 20:59

>>15
gcc win32 codeblocks full opt.
a: 0.015s av. over 10 runs
b: 0.032s av. over 10 runs

Name: Anonymous 2007-11-22 21:03

>>18
which is a and which is b?

Name: Anonymous 2007-11-22 21:04

>>13
% gcc -O2 hello.c -o helloc
% g++ -O2 hello.cpp -o hellocpp
% strip helloc hellocpp
% ls -l helloc hellocpp
-rwxr-xr-x 1 expert progmr 13184 2007-11-23 02:01 helloc
-rwxr-xr-x 1 expert progmr 17780 2007-11-23 02:01 hellocpp

Name: Anonymous 2007-11-22 21:38

>>19
a: printf
b: cout

Name: Anonymous 2007-11-22 23:29

I would only use c++ i/o when stdio isnt adaquete, such as displaying int64s, cout is overloaded to work with 64 and 128 bit (i think) binaries

Name: Anonymous 2007-11-22 23:33

>>22
Or you can lrn codez and actually program properly rather than using moronic fucking languagehacks.

Name: Anonymous 2007-11-23 3:07

cout doesn't have to run a fucking interpreter with % tags and parameters scattered in different places.

Name: Anonymous 2007-11-23 4:19

>>24
You make it sound like parsing a string and interpolating values when you encounter a sigil is somehow computationally intensive.

Name: Anonymous 2007-11-23 5:52

>>24
You make it sound like writing friend functions of operator<<(ostream &, T &) is somehow the lesser evil to an extremely minor performance difference.

(I mean, it didn't matter even on a kilohetrz-clocked PDP-8!)

Name: Anonymous 2007-11-23 5:59

OH FOR FUCKS SAKE ?? 26 POSTS ON THIS THREAD GOOOD DAMN IT SHUT UP EVERYONE IM TRYING TO SLEEP

Name: Anonymous 2007-11-23 7:06

>>24
Enjoy your iomanip

Name: Anonymous 2007-11-23 8:05

>>1
Stroustrup is the biggest troll ever, who the fuck would really think about overloading bitwise operators and saying that it's better learning C++ without any knowledge of C. Listen to people like Paul Graham and The Sussman they know what they are talking about.

Name: Anonymous 2007-11-23 9:23

>>29
Truth

Name: Anonymous 2007-11-23 11:51

>>22
printf() in 64-bit and 128-bit environments would by necessity support outputting those sizes.

>>24
There's fwrite(), puts() and other output functions that don't do formatting if you don't need it. But most of the time you do need the formatting, and that's when something like "%08X-%08X-%c|%d/%d%%" in a single printf() is better than a whole bunch of setxxx() calls.

Name: Anonymous 2007-11-23 13:17

>>31
Hey, isn't that VALID PERL CODE?

Name: Anonymous 2007-11-23 13:18

>>32
YOURE AN IDIOT

Name: Anonymous 2007-11-24 12:25

iostream = fail and aids, with a cherry on top.

Name: Anonymous 2007-11-24 12:32

>>34
Ahh, nothing like a convincing argument!

Name: Anonymous 2007-11-24 12:40

>>35

You must be new here

Name: Anonymous 2007-11-24 12:50

>>36
It seems that, my friend, that
 you
  have
   just
    been

 ##TROLLED##

     !!!

Name: Anonymous 2007-11-24 12:57

>>37

No, this was anticipated. It was found that deterring ill behaved new users was of greater importance than being `trolled' by an established member of this community.

Name: Anonymous 2007-11-24 13:28

>>38
no

Name: Anonymous 2007-11-24 13:35

>>39

No.

Name: Anonymous 2007-11-24 13:39

>>40
No.

Name: Anonymous 2007-11-24 13:49

      fuckyou
     fuckyou
    fuckyou
   fuckyou
  fuckyou
 fuckyou
fuckyou

Name: Anonymous 2007-11-24 17:17

>>23

lol fail

Name: Anonymous 2007-11-24 17:36

>>35-40
HAHAHAHA
YOU THINK YOURE THOUGH UH ?
I HAVE ONE WORD FOR YOU
  THE FORCED INDENTATION OF THE CODE
GET IT ?
I DONT THINK SO
YOU DONT KNOW ABOUT MY OTHER CAR I GUESS ?
ITS A CDR
AND IS PRONOUNCED ``CUDDER''

OK YOU FUQIN ANGERED AN EXPERT PROGRAMMER
THIS IS
/prog/
YOU ARE ALLOWED TO POST HERE ONLY IF YOU HAVE ACHIEVED SATORI
PROGRAMMING IS ALL ABOUT ``ABSTRACT BULLSHITE'' THAT YOU WILL NEVER COMPREHEND
I HAVE READ SICP
IF ITS NOT DONE YOU HAVE TO
TOO BAD RUBY ON RAILS IS SLOW AS FUCK
BBCODE AND
((SCHEME)) ARE THE ULTIMATE LANGUAGES
ALSO
WELCOME TO
/prog/
EVERY THREAD WILL BE REPLIED TO
NO EXCEPTION

Name: Anonymous 2007-11-24 17:51

>>40
no


COMBOWIN

Name: Anonymous 2007-11-24 19:07

>>17
Not to mention printf() is vulnerable to buffer overflows OH SNAP

Name: Anonymous 2007-11-24 22:03

>>46
Uhh... no it isn't, since it's writing directly to stdout and not touching the stack. sprintf, strcpy, strcat, gets, etc... are vuln to buffer overflow.

Name: Anonymous 2007-11-24 22:04

fwrite > printf > cout

Get a fucking clue

Name: Anonymous 2007-11-25 2:00

>>46
Dumbass.

Name: Anonymous 2007-11-25 3:11

>>46
gtfo my bikeshed

Name: Anonymous 2007-11-25 5:11

>>1
Once you start working on important things the usefulness of iostream really starts to decline, because the important things have a GUI, or you're working in places far awar from where the output and input are generated. About the only thing for iostream to do in programs like these is update error logs.  Especially if you consider what C++  spends most of its time doing in the real world.

If you're just doing your homework or something then there is no need to listen to anyone's performance claims, but it probably doesn't matter anyway.

Name: Anonymous 2007-11-25 5:49

YES!!!!

..um

Name: Anonymous 2007-11-26 19:30

USE scheme()

Name: malpower 2007-11-26 19:54

What is scheme()?

Name: Anonymous 2007-11-26 20:26

>>54
I've emailed you the details

Name: Anonymous 2007-11-26 21:46

>>54
Read SICP.

Name: Anonymous 2007-11-27 0:03

>>56
Read "How to tell people to read SICP."

Name: Anonymous 2007-11-27 1:05

YUS!>>39
>>39

Name: Anonymous 2007-11-27 11:35

A small Program I wrote:

with <iostream>: over 200KB
with <cstdio>: 6KB

luls

Name: Anonymous 2007-11-27 11:42

>>59
Compile with -O5 and they'll both reduce down to 4KB.

Name: Anonymous 2007-11-27 12:00

/prog/ needs a BAN HAMMER for shitfuckers who can't fucking code.  We're not your teacher, faggots.

Name: Anonymous 2007-11-27 12:03

>>60
Aren't the -O options just for better performance?

Name: Anonymous 2007-11-27 12:07

>>40
No.

Name: Anonymous 2007-11-27 14:41

>>31
not if you have a 32 bit environment and needs to do 64 bit arithmetic somehow, then cout could already display it, and I dont think the commitee added a int64 modifier to printf, %ld is long %lld is long long?

Name: Anonymous 2007-11-27 16:39

>>62
They're the optimization switches. They change how gcc translates it to ASM.

Name: Anonymous 2007-11-27 19:50

>>64
Look into <stdint.h> and <inttypes.h>
They've added stuff like uint64_t for example, and to print it using printf() you write

uint64_t n = UINT64_MAX;
printf("%"PRIu64"\n", n);

Name: Anonymous 2007-11-27 22:03

>>66
you meant \" right?

Name: Anonymous 2007-11-27 22:16

>>67
You missed the

#define PRIu64 ); printf( "\"PRIu64\"

Which might have made the damned thing compile. Stupid fucking C-preprocessor.

Name: Anonymous 2007-11-28 4:47

>>68
#define PRIu64 llu

Name: 66 2007-11-28 8:03

>>67,68
fucking idiots
>>69
Well it might be llu.

Name: Anonymous 2007-11-28 8:23

>>67
echo -e "#include <inttypes.h>\nPRIu64"|cc -E -|tail -n1

Name: Anonymous 2007-11-28 9:02

>>71
doesn't work:
$ echo -e "#include <inttypes.h>\nPRIu64"|cc -E -|tail -n1
-e #include <inttypes.h>\nPRIu64


this works:
$ echo "#include <inttypes.h>\
PRIu64"|cc -E -|tail -n1
"llu"

Name: Anonymous 2007-11-28 10:03

>>72
try with \r\n.
If that doesn't work, then you are doing something wrong.

Name: Anonymous 2007-11-28 10:26

Fatal error! Message could not be posted.

Please post threads less often!

Name: Fred? 2007-11-28 20:04

printf is in stdio and cout in iostream and well printf is predominantly for C and cout for C++ they can both be compiled under a C++ compiler.

Shouldn't really be a concern to use either but cout is probably particularly easier to use than printf.

Name: Anonymous 2007-11-28 20:08

printf is better for formatting shit.
cout is better for concatenating shit.

thread over.

Name: Anonymous 2007-11-28 20:17

>>76
fwrite is better for everything.

Name: Anonymous 2007-11-28 20:19

>>40
NO

Name: Anonymous 2007-11-28 20:25

>>51
You faggot. The most important programs are terminal programs.

Name: Anonymous 2007-11-28 20:26

>>79
No.

Name: Anonymous 2007-11-28 20:27

hay guyz, which is best to use, endl or \n???

Name: Anonymous 2007-11-28 20:28

>>79
Semi-expert proggggrammer

>>82
uze endl

Name: Anonymous 2007-11-28 20:31

>>79
>>80
>>81
>>82
Same fag.

Name: Anonymous 2007-11-28 20:35

>>83
>>83
>>83
>>83
Same fag.

Name: Anonymous 2007-11-28 20:44

C++ is for fags, period.

Name: Anonymous 2007-11-28 20:46

>>84
>>84
>>84
>>84
Same fag.

Name: Anonymous 2009-03-06 8:15

Wrote an x86 assembler   in assembler when   I was 12   years old You   SOCKETS NATEHRE IS   NO FUK CING   MACHIEN THAT DOES   things very differently.

Name: Anonymous 2010-12-24 9:02

Name: Anonymous 2011-02-04 13:48

Name: Anonymous 2011-02-04 15:59

Name: Anonymous 2011-02-04 17:16

Don't change these.
Name: Email:
Entire Thread Thread List