Thread: Cin & Cout VS. Scanf & Printf

  1. #16
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,164
    Originally posted by blackrat364
    printf may be a bit easier for the incredibly complex things like that, but for simply displaying a string or an int, or getting either from the user, cin and cout are easier.
    This is what we call the DUH factor. But as a developer, I rarely need to simply display a value. I have to display values in a way that the user can use, which means formatting, sometimes extensive formatting.
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

  2. #17
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,164
    Originally posted by mart_man00
    If C++ is a superset of C why did they even bother with cin/cout?
    Because cin/cout are designed to be objects, part of the OO of C++. printf et al are not OO, they are the procedural way of doing I/O

    C++ at times seems more like a different language/knock off.
    It is a different language, but it kept the base it was designed from. This makes it difficult sometimes to keep in one style. For example, a fully C++ program can fall back on C's I/O routine, and you can write a program completely in C and use the I/O from C++. I see a lot of hybrid code.

    The whole object oriented stuff sounds great, I think ill try to avoid c++ as long as possible and give Objective C a shot. I havnt heard much, but i havent heard that they cheated either.
    Unless programming is just a hobby, don't. C++ is where the industry is. It's harder and harder to find positions that want just a C programmer.
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

  3. #18
    Registered User
    Join Date
    Jul 2002
    Posts
    913
    Because cin/cout are designed to be objects, part of the OO of C++. printf et al are not OO, they are the procedural way of doing I/O
    How are cin/cout objects? Wouldnt it need to be more Java style to be objects? Wouldnt the terminal need to be a class?

    What exactly seperates Objective C from C++? Isnt Objective supposed to have Classes and other OOP? Then isnt the only difference the rewrites?

    Unless programming is just a hobby, don't. C++ is where the industry is. It's harder and harder to find positions that want just a C programmer.
    Yeah, I forgot about that one, to bad....

  4. #19
    Pursuing knowledge confuted's Avatar
    Join Date
    Jun 2002
    Posts
    1,916
    cin and cout are objects because you can do things such as
    cin.getline();

    (just for an example. They have numerous other methods as well)
    Away.

  5. #20
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    Originally posted by XSquared
    This won't work.
    Code:
    cout << setfill('0') << setw(2) << hex << hval << setfill(' ') << dec << setw(12) << dval
          << "  val=" << setw(7) << setprecision(3) << fval << endl;
    http://cplusplus.com/ref/iostream/io...precision.html
    Thanks XSquared. Funny thing is, it prints like printf() on my old compiler.

    Which brings up a question:
    Is there any easy way to print money amounts with cout? If you use floats, it appears not.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. IF CONDITION plese help
    By birumut in forum C Programming
    Replies: 12
    Last Post: 03-06-2009, 09:48 PM
  2. I need help on this particular Linked List problem
    By sangken in forum C Programming
    Replies: 11
    Last Post: 08-06-2006, 12:26 AM
  3. help with basic program
    By JOlszewski in forum C Programming
    Replies: 3
    Last Post: 02-01-2006, 04:19 PM
  4. error in program????
    By SpEkTrE in forum C Programming
    Replies: 5
    Last Post: 11-24-2003, 06:16 PM
  5. Drawing tables in C
    By stanoman in forum C Programming
    Replies: 5
    Last Post: 10-09-2003, 10:14 AM