Difference from Cout to printf in C++

Asked

Viewed 6,106 times

6

I wonder what difference I use in C++ cout and printf, it’s all the same?

2 answers

5


No, they are completely different, although they have more or less similar purposes.

cout works with streams of data. Those streams can be customized for each type of data.

The function printf() is a very simple normal function originally created for the C language and which has been maintained for compatibility reasons and because in some cases it may be more suitable than cout.

Usually the cout not only is it more suitable and simple to use in C++, but it also has better performance. It has a question on incoming counterparties.

See more about the cout here.

And how does the printf().

Recently they considered the stream something bad for much of the scenarios similar to the printf() are creating a formatting solution for optional use.

-3

#include <stdio.h>
#include <iostream>
int main(){
    printf("Eu posso misturar printf com cout?");
    cout<<"Em?";
    return 0;
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.