Thread: Library of C++ opposed to C

  1. #1
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584

    Library of C++ opposed to C

    I am a C programmer. C programmer's use the stdio.h library for the basic I/O functions. I am working on C++. Learning it. I am very fluent with stdio.h. What is iostream.h like? Are the functions the same? I realize that instead of printf, you would use cout, cin, cerr and that sort. But is it still sscanf, scanf, sprintf, fprintf? Thanks.

    --Garfield
    1978 Silver Anniversary Corvette

  2. #2
    geek SilentStrike's Avatar
    Join Date
    Aug 2001
    Location
    NJ
    Posts
    1,141
    You can stick with the C I/O stuff if you want, a lot of people like how it is easier to change out to output the primitive stuff in different formats anyway.

    I am pretty sure there is a C++ counterpart for everything with C I/O. There are output string streams (write to strings rather than stdout or files), called ostrstream, instead of using sprintf. Likewise, there are input streams for reading from strings, istrstream, rather than sscanf. I don't know what fprintf is for, however, so I can't post a C++ equivlient.
    Prove you can code in C++ or C# at TopCoder, referrer rrenaud
    Read my livejournal

  3. #3
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    fprintf is writing to a file. You write the string to a file after you open it for writable access. So, if I wanted to use some C functions and C++ functions, then I would do:
    Code:
    #include <iostream.h>
    #include <stdio.h>
    ...
    I guess that's not too bad. Thanks.

    --Garfield
    1978 Silver Anniversary Corvette

  4. #4
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912

    1st Guy/conio.h

    Like the first guy said, you can still use stdio.h, but you may also want to consider learning how to use conio.h as well. I find a lot more capabilities in it. Just a quick look at the header file will reveal a lot of things like the #define statements used to allow you to use color. Hope this helps.

    _________________________
    Sean Mackrory
    [email protected]

  5. #5
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    Thanks, guys, I appreciate it!
    1978 Silver Anniversary Corvette

  6. #6
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Strictly speaking, C++ is an extension of the C language. Therefore, as long as there are no incompatibilities between the functions being used, (think fgets and scanf!), then there should be no problems with mixing C function calls in a C++ program.

    The STL(Standard Template Library) is truly extensive. Literally hundreds of algorithms and numerous methodologies at your fingertips.

  7. #7
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    fgets and scanf won't work with C++!!!??? Why not?
    1978 Silver Anniversary Corvette

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. What's an import library?
    By chiefmonkey in forum C++ Programming
    Replies: 1
    Last Post: 06-19-2009, 05:00 PM
  2. Property Set Library (PSL) - Announcement
    By vultur_gryphus in forum Projects and Job Recruitment
    Replies: 0
    Last Post: 05-29-2008, 06:04 AM
  3. Makefile for a library
    By sirmoreno in forum Linux Programming
    Replies: 5
    Last Post: 06-04-2006, 04:52 AM
  4. very weird .h problem
    By royuco77 in forum C++ Programming
    Replies: 1
    Last Post: 09-11-2005, 07:55 AM
  5. better c string functions
    By samps005 in forum C Programming
    Replies: 8
    Last Post: 11-04-2003, 01:28 PM