Can I replace cout and printf? [duplicate]

1

What is the difference between cout and printf ?

I learned using printf and scanf , but in an online course I see the teacher using cout and some pages also use cout , but others use printf ...

Can I replace cout with good old printf ?

    
asked by anonymous 16.12.2017 / 00:45

2 answers

2

In general, you should. cout is C ++, printf() is C. They are completely different, but the goal is the same .

    
16.12.2017 / 00:53
0

cout is owned by C ++ and is in the iostream header

example:

#include <iostream>
#include <string>

int main(int argc, char* argv[])
{
    std::string nome; //String que guardará o valor de nome

    //cin equivale á scanf() em C++
    std::cin >> nome; //Pega o valor digitado no console e coloca em nome 

    //cout equivale a printf() em C++
    std::cout << nome;

    //Outro forma de usar cout
    std::cout << "Nome: " << nome << " Idade: " << 10 << "\n";
    return 0;
}
    
19.12.2017 / 13:07