Can I replace Cout and printf?

Asked

Viewed 1,323 times

1

What’s the difference between cout and printf?

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

I can replace the cout by good old printf?

  • Duplicate question. Title does not reflect content. You can change?

2 answers

2


  • Aaahh, but C++ and C are only one language more complete than the other, right?

  • Not exactly, one borrowed some of the other’s stuff, that’s all.

  • Ata vlw Manin tmj

0

Cout belongs to 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;
}

Browser other questions tagged

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