Quantcast
Channel: 'printf' vs. 'cout' in C++ - Stack Overflow
Browsing all 19 articles
Browse latest View live
↧

Answer by wohlstad for 'printf' vs. 'cout' in C++

Update 2023:The idiomatic way to print to the console from c++23 is supposed to be with std::print, which uses {} placeholders in the format string syntax (see below):#include <print>int main(){...

View Article


Answer by Wesley for 'printf' vs. 'cout' in C++

TL;DR: Always do your own research, in regard of generated machine code size, performance, readability and coding time before trusting random comments online, including this one.I'm no expert. I just...

View Article

Answer by Daniel Woodard for 'printf' vs. 'cout' in C++

I'm not a programmer, but I have been a human factors engineer. I feel a programming language should be easy to learn, understand and use, and this requires that it have a simple and consistent...

View Article

Answer by Apollo for 'printf' vs. 'cout' in C++

I'd like to point out that if you want to play with threads in C++, if you use cout you can get some interesting results.Consider this code:#include <string>#include <iostream>#include...

View Article

Answer by Bill Weinman for 'printf' vs. 'cout' in C++

Two points not otherwise mentioned here that I find significant: 1) cout carries a lot of baggage if you're not already using the STL. It adds over twice as much code to your object file as printf....

View Article


Answer by john for 'printf' vs. 'cout' in C++

printf is a function whereas cout is a variable.

View Article

Answer by Kamila Borowska for 'printf' vs. 'cout' in C++

I'm surprised that everyone in this question claims that std::cout is way better than printf, even if the question just asked for differences. Now, there is a difference - std::cout is C++, and printf...

View Article

Answer by skan for 'printf' vs. 'cout' in C++

More differences:"printf" returns an integer value (equal to the number of characters printed) and "cout" does not return anythingAnd.cout << "y = "<< 7; is not atomic.printf("%s = %d",...

View Article


Answer by bmorel for 'printf' vs. 'cout' in C++

I would like say that extensibility lack of printf is not entirely true:In C, it is true. But in C, there are no real classes.In C++, it is possible to overload cast operator, so, overloading a char*...

View Article


Answer by LuP for 'printf' vs. 'cout' in C++

Of course you can write "something" a bit better to keep maintenance:#include <iostream>#include <cstdlib>using namespace std;class Something{ public: Something(int x, int y, int z) : a(x),...

View Article

Answer by Daniel for 'printf' vs. 'cout' in C++

With primitives, it probably doesn't matter entirely which one you use. I say where it gets usefulness is when you want to output complex objects.For example, if you have a class,#include...

View Article

Answer by mishal153 for 'printf' vs. 'cout' in C++

For me, the real differences which would make me go for 'cout' rather than 'printf' are:1) << operator can be overloaded for my classes.2) Output stream for cout can be easily changed to a file...

View Article

Answer by Thomas for 'printf' vs. 'cout' in C++

People often claim that printf is much faster. This is largely a myth. I just tested it, with the following results:cout with only endl 1461.310252 mscout with only '\n' 343.080217 msprintf with only...

View Article


Answer by Mikeage for 'printf' vs. 'cout' in C++

From the C++ FAQ:[15.1] Why should I use <iostream> instead of the traditional <cstdio>?Increase type safety, reduce errors, allow extensibility, and provide inheritability.printf() is...

View Article

Answer by scatman for 'printf' vs. 'cout' in C++

cout<< "Hello";printf("%s", "Hello"); Both are used to print values. They have completely different syntax. C++ has both, Conly has printf.

View Article


Answer by Marcelo Cantos for 'printf' vs. 'cout' in C++

One is a function that prints to stdout. The other is an object that provides several member functions and overloads of operator<< that print to stdout. There are many more differences that I...

View Article

Answer by Kyle Rosendo for 'printf' vs. 'cout' in C++

And I quote:In high level terms, the main differences are type safety (cstdio doesn't have it), performance (most iostreams implementations are slower than the cstdio ones) and extensibility (iostreams...

View Article


'printf' vs. 'cout' in C++

What is the difference between printf() and cout in C++?

View Article

Answer by vitaut for 'printf' vs. 'cout' in C++

APIprintf uses a replacement-based API with placeholders starting with % replaced with formatted arguments:printf("The answer is %d.\n", answer);cout or, more generally, ostreams use a...

View Article
Browsing all 19 articles
Browse latest View live