Categories > Coding > C++ >

(Probably annoying by now) std::cout or std::printf?

TERIHAX

i say im gay as a joke 🙀

Posts: 2240

Threads: 102

Joined: Jul, 2020

Reputation: 32

Posted

title

 

i asked chatgpt and i still cant decide

 

srry if this is getting annoying

  • 0

Posts: 2

Threads: 0

Joined: Apr, 2023

Reputation: 0

Replied

printf stands for print format

or the og spell it printfffffffffffffeeee

It's on the stdio.h header which is the std input output lib for C and it's the standard way of printing to the console using C, but since C++ still maintains C backwards compatibility so it's still there and to make it easier to access so they include it in the std namespace i guess.

 

There's not much a difference to be considered should I use this or that. Pretty sure printf is just printing string to conout using placeholder formatting like

 

printf("Hello, %s", "Bob"); %s for string or %d for digit or int stuff so that the %s is replaced by "Bob" or whatever I can't explain really well icl

 

Doesn't matter afaik, I mean it doesn't affect your program stuff that much so yeah stop 😶

Comments

TERIHAX 32 Reputation

Commented

wdym by "stop" at the end, should i stop making these annoying c++ threads

  • 0

rilyn 0 Reputation

Commented

@TERIHAX No. don't afraid to ask questions, just stop asking question like this.

  • 0

TERIHAX 32 Reputation

Commented

@rilyn alright

  • 0

  • 0

0x90

dingleberry#2286

vip

Posts: 249

Threads: 26

Joined: Dec, 2020

Reputation: 28

Replied

std::cout is safe whilst printf may not be.

printf uses C runtime formatting which is notorious for causing some of the biggest bugs in history and causing billions of dollars in damage, outputting a string in printf is dangerous, whilst formatting them through a stream is not.

Comments

TERIHAX 32 Reputation

Commented

damn i didnt know it was that bad, also i rarely see you active anymore, what happened?

  • 0

SeizureSalad 40 Reputation

Commented

he has better things to do

  • 0

TERIHAX 32 Reputation

Commented

@SeizureSalad oh i can understand

  • 0

Added

@0x90 prob stupid question again, is using the system() function safe? like if i want to clear the console, like system("cls");

  • 0

Cyros 20 Reputation

Commented

@TERIHAX system isn't safe i dont think

  • 0

  • 0

Cyros

Revision

Posts: 1060

Threads: 49

Joined: Feb, 2021

Reputation: 20

Replied

I use printf("yes") because I don't need weird-looking arrows in C++ that may look out of place

anyways it's probably better to use std::cout instead of printf() but I've never really had any issues with either so you can decide I guess

 

Afaik type safety; std::cout is 100% better, though printf() has better format flexibility
Reasons vary on what you are doing, if you want to format stuff easily it's recommended to use printf() but anything else should be handled with std::cout. Issues can occur with printf() like a data type doesn't match in printf() which causes a runtime error (afaik)

In an Object Oriented Approach or whatever it's better to use std::cout because it allows chaining and customizability of its behaviour (I think, but not sure)

Comments

TERIHAX 32 Reputation

Commented

alr ill just stick to cout for now

  • 0

  • 0

We Hate VOID

Posts: 2014

Threads: 198

Joined: Apr, 2021

Reputation: 16

Replied

std::cout cause yes

Comments

TERIHAX 32 Reputation

Commented

ok

 

/charesadasd

  • 0

  • 0

Random quote here...

Posts: 140

Threads: 28

Joined: Feb, 2021

Reputation: 4

Replied

I recommend you to use printf, as it is faster, and simpler to use.

printf(char *a, ...);

The argument a represents a pointer to the first character of a string that contains the format (example: "Text: %s\nNumber: %d\n");

The argument(s) ... represents either pointers to first character in string that represents `%s`, or just a number, or some other value...

Comments

luxiferrwoo -4 Reputation

Commented

no, and i dont think i have to explain why

  • 0

  • 0

Contribute to Express, an open-source ROBLOX exploit written fully in C.

Request

RequestJr

vip

Posts: 15

Threads: 1

Joined: Jul, 2023

Reputation: 6

Replied

std::cout 100%

Comments

TERIHAX 32 Reputation

Commented

wtf is with ur pfp

  • 0

Request 6 Reputation

Commented

shhh, science

  • 0

TERIHAX 32 Reputation

Commented

@Request understandable

  • 0

  • 0

silly billy 🍎🍎🍎🍎

yvneEnvy

<><><<>>><<>

Posts: 306

Threads: 47

Joined: Mar, 2023

Reputation: 3

Replied

STD = S*xualy trasmitted d- 

 

Printf = Pratical retar*dation international news torment function

  • 2

Users viewing this thread:

( Members: 0, Guests: 1, Total: 1 )