Thread: confused

  1. #1
    Registered User
    Join Date
    May 2009
    Posts
    23

    Question confused

    can we use printf and scanf in C++ cause some guys just confused me

  2. #2
    Banned ಠ_ಠ's Avatar
    Join Date
    Mar 2009
    Posts
    687
    yes.
    ╔╗╔══╦╗
    ║║║╔╗║║
    ║╚╣╚╝║╚╗
    ╚═╩══╩═╝

  3. #3
    Programming Ninja In-T...
    Join Date
    May 2009
    Posts
    827

    Question

    Quote Originally Posted by ಠ_ಠ View Post
    yes.
    Really? :shock: That's news to me...
    I thought that was only for C.
    In C++, the "cout" and "cin" functions are pretty much their C++ equivalents.
    Last edited by Programmer_P; 05-25-2009 at 10:46 PM.

  4. #4
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    You can, but in most cases it makes more sense to use the C++ equivalents.

  5. #5
    Banned ಠ_ಠ's Avatar
    Join Date
    Mar 2009
    Posts
    687
    but not necessarily when you want your input formatted in a certain way.
    example: "mm/dd/yyyy"
    ╔╗╔══╦╗
    ║║║╔╗║║
    ║╚╣╚╝║╚╗
    ╚═╩══╩═╝

  6. #6
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    The standard for C++ says that (essentially) any existing C code should still work as C++ code, so from that perspective, scanf/printf are valid C++ code.

    Some would of course say that "then it's not proper C++", but that is a bit of a different topic.

    However, there are some interesting limitations:
    Both stdio FILE functions (e.g. stdin and stdout that is used implicitly in printf and scanf) and the C++ streams (e.g cin/cout) are allowed to buffer data. This means that if you MIX cin/cout with stdin/stdout operations, you may find stuff going wrong. There is a sync_with_stdio function that ensures that the different I/O mechanisms are in sync.
    sync_with_stdio - C++ Reference

    Note that since this involves implementation specific components, it may seem unnecessary to sync these things, and then you change the compiler (version or supplier), or compile the code for a different OS (or even turn off debugging), and it falls apart.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  7. #7
    Registered User
    Join Date
    May 2007
    Posts
    147
    As to formatting data with streams, boost has a nice formatting library for use with streams that outdoes printf formatting.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Confused about Memory
    By gL_nEwB in forum C++ Programming
    Replies: 22
    Last Post: 06-20-2006, 07:32 PM
  2. why wont this compile?!? :confused:
    By jdude in forum C++ Programming
    Replies: 5
    Last Post: 11-25-2004, 01:13 AM
  3. So Now Im getting confused?!?!?
    By zergdeath1 in forum C++ Programming
    Replies: 11
    Last Post: 03-06-2004, 05:41 PM
  4. confused.. in selecting my line of deapth
    By jawwadalam in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 05-04-2003, 01:21 PM
  5. Extern Question, really confused
    By SourceCode in forum C Programming
    Replies: 10
    Last Post: 03-26-2003, 11:11 PM