Thread: Simple Questions

  1. #1
    Unregistered
    Guest

    Exclamation Simple Questions

    Hi there, I'm fairly new at C++ so I just have a few quick questions

    First of all, what's the difference between the printf and cout command and when should I use each one. And second, what's the difference between the scanf and cin command and when should I use which one?

    Thanks for the advice ....

  2. #2
    Unregistered
    Guest
    C I/Orintf() and sscanf()

    C++ I/O:cout and cin


    You can use both since C++ is a more advanced form of C (in simple terms). It is all a matter of preference.

  3. #3
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,138
    Sorry about the smiley, I forgot to turn off them. Btw, that last post was me.

  4. #4
    "The Oldest Member Here" Xterria's Avatar
    Join Date
    Sep 2001
    Location
    Buffalo, NY
    Posts
    1,039
    if you use printf(), outputing variables are little harder.
    for example, we have x as a variable:
    ////////////////
    //with cout
    cout << var;
    //
    now with printf() you have to know what you want to output, weather its a number or character(s).
    //
    printf("%d", var);
    //you use this to output var in number form
    printf("%c" var);
    //you use this to output var in character form
    ///////////////

  5. #5
    Golfinguy is right,

    sscanf() and printf() are the old C functions for Input and Output

    cout and cin and the equivalents in the newer C++

    The C++ version is easier to use.

    Just get used to seeing the old C style functions as C is at least 20 years old and I beleive older, alot of code is written in plain C - the old farts still use C becuase they can't be taught new tricks.
    My Avatar says: "Stay in School"

    Rocco is the Boy!
    "SHUT YOUR LIPS..."

  6. #6
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >the old farts still use C becuase they can't be taught new tricks.
    Don't be so quick to assume that, printf does have advantages over cout. Though I prefer to follow a guideline of using C++ I/O when coding C++ and C I/O when coding C. Of course there are exceptions, use whatever works best if you want to be truly flexible

    -Prelude
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. questions....so many questions about random numbers....
    By face_master in forum C++ Programming
    Replies: 2
    Last Post: 07-30-2009, 08:47 AM
  2. A couple questions
    By Flakster in forum C++ Programming
    Replies: 7
    Last Post: 08-09-2005, 01:22 PM
  3. Few simple questions...
    By Shane in forum C++ Programming
    Replies: 9
    Last Post: 08-06-2005, 02:40 AM
  4. A few simple batch questions
    By sean in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 07-02-2003, 01:35 PM
  5. questions questions questions.....
    By mfc2themax in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 08-14-2001, 07:22 AM