Mixing C and C++

Discussion in 'C++' started by Salman, Apr 18, 2007.

  1. Salman

    Salman Guest

    How to mix C and C++ ?
     
    Salman, Apr 18, 2007
    #1
    1. Advertising

  2. Salman

    Ian Collins Guest

    Salman wrote:
    > How to mix C and C++ ?
    >

    In what context? Every time you call into your operating system you are
    using C code in C++. Do you want to use C++ objects from C? If so, you
    have to use interface functions declared as extern "C" in you C++ code.

    --
    Ian Collins.
     
    Ian Collins, Apr 18, 2007
    #2
    1. Advertising

  3. Salman wrote:
    > How to mix C and C++ ?


    Carefully. Usually with a sprinkle of 'extern "C" ' where
    needed. Also, recommended to use different bowls until ready
    to link. Do you have any particular question?

    V
     
    Victor Bazarov, Apr 18, 2007
    #3
  4. Salman

    Salman Guest

    On Apr 18, 4:14 am, "Victor Bazarov" <> wrote:
    > Salman wrote:
    > > How to mix C and C++ ?

    >
    > Carefully. Usually with a sprinkle of 'extern "C" ' where
    > needed. Also, recommended to use different bowls until ready
    > to link. Do you have any particular question?
    >
    > V



    i want to use both type of file streams i.e FILE and fstream in my
    program. Forget abt the reason why i need them. Is this possible to
    have both in my code? Its not working, tell me how to?
     
    Salman, Apr 18, 2007
    #4
  5. Salman wrote:
    > On Apr 18, 4:14 am, "Victor Bazarov" <> wrote:
    >> Salman wrote:
    >>> How to mix C and C++ ?

    >>
    >> Carefully. Usually with a sprinkle of 'extern "C" ' where
    >> needed. Also, recommended to use different bowls until ready
    >> to link. Do you have any particular question?
    >>
    >> V

    >
    >
    > i want to use both type of file streams i.e FILE and fstream in my
    > program. Forget abt the reason why i need them. Is this possible to
    > have both in my code?


    Sure. What's the problem?

    > Its not working, tell me how to?


    I don't understand your last sentence. If you have code that doesn't
    work, follow FAQ 5.8's recommendations. If you don't, there is plenty
    of examples of using both streams and FILEs on the web.

    V
    --
    Please remove capital 'A's when replying by e-mail
    I do not respond to top-posted replies, please don't ask
     
    Victor Bazarov, Apr 18, 2007
    #5
  6. Salman

    Guest

    On Apr 17, 6:06 pm, Salman <> wrote:
    > How to mix C and C++ ?


    Anything you can do in C can be done in C++. Write in a C++ file and
    only use C++ when you want to.

     
    , Apr 18, 2007
    #6
  7. On 18 Apr, 01:54, Salman <> wrote:
    > On Apr 18, 4:14 am, "Victor Bazarov" <> wrote:
    >
    > > Salman wrote:
    > > > How to mix C and C++ ?

    >
    > > Carefully. Usually with a sprinkle of 'extern "C" ' where
    > > needed. Also, recommended to use different bowls until ready
    > > to link. Do you have any particular question?

    >
    > > V

    >
    > i want to use both type of file streams i.e FILE and fstream in my
    > program.


    Remember that the C standard library is part of C++ so

    #include <cstdio>
    #include <iostream>

    and you are good to go.

    > Forget abt the reason why i need them.


    Usually the reason for a need can tell quite a lot about how to
    satisfy it, so most of us usually likes to know the reason for
    something since it means that we'll be better able to answer the
    question. It's not uncommon for people to ask about how to do
    something that can be done in a much better way, but if they don't
    tell what they are trying to do how will we be able to tell?

    > Is this possible to have both in my code? Its not working, tell me how to?


    How is it not working? Error-messages etc. would be helpful, so would
    the code they does not work. Are you trying to use a fread() on a
    fstream or something like that?

    --
    Erik Wikström
     
    =?iso-8859-1?q?Erik_Wikstr=F6m?=, Apr 18, 2007
    #7
  8. Salman

    Guest

    On Apr 17, 11:19 pm, Erik Wikström <> wrote:
    > On 18 Apr, 01:54, Salman <> wrote:
    >
    > > On Apr 18, 4:14 am, "Victor Bazarov" <> wrote:

    >
    > > > Salman wrote:
    > > > > How to mix C and C++ ?

    >
    > > > Carefully. Usually with a sprinkle of 'extern "C" ' where
    > > > needed. Also, recommended to use different bowls until ready
    > > > to link. Do you have any particular question?

    >
    > > > V

    >
    > > i want to use both type of file streams i.e FILE and fstream in my
    > > program.

    >
    > Remember that the C standard library is part of C++ so
    >
    > #include <cstdio>
    > #include <iostream>
    >
    > and you are good to go.
    >
    > > Forget abt the reason why i need them.

    >
    > Usually the reason for a need can tell quite a lot about how to
    > satisfy it, so most of us usually likes to know the reason for
    > something since it means that we'll be better able to answer the
    > question. It's not uncommon for people to ask about how to do
    > something that can be done in a much better way, but if they don't
    > tell what they are trying to do how will we be able to tell?
    >
    > > Is this possible to have both in my code? Its not working, tell me how to?

    >
    > How is it not working? Error-messages etc. would be helpful, so would
    > the code they does not work. Are you trying to use a fread() on a
    > fstream or something like that?
    >
    > --
    > Erik Wikström


    NO,IT IS NOT POSSIBLE TO MIX C,C++
     
    , Apr 18, 2007
    #8
  9. Salman

    Ian Collins Guest

    wrote:
    >
    > NO,IT IS NOT POSSIBLE TO MIX C,C++
    >

    Nonsense.

    --
    Ian Collins.
     
    Ian Collins, Apr 18, 2007
    #9
  10. Salman

    Me Guest

    On Tue, 17 Apr 2007 16:54:24 -0700, Noone wrote:

    > On Apr 18, 4:14 am, "Victor Bazarov" <> wrote:
    >> Salman wrote:
    >> > How to mix C and C++ ?

    >>
    >> Carefully. Usually with a sprinkle of 'extern "C" ' where needed.
    >> Also, recommended to use different bowls until ready to link. Do you
    >> have any particular question?
    >>
    >> V

    >
    >
    > i want to use both type of file streams i.e FILE and fstream in my
    > program. Forget abt the reason why i need them. Is this possible to have
    > both in my code? Its not working, tell me how to?


    The STL streams classes are not generally compatible with C style FILE*
    operations. There are some streambuf hacks to get around this but you
    should generally choose one or the other style of file IO. I like the
    streams interface but not being able to easily get an (int fd) for a file
    can be annoying, especially if the file is a device...
     
    Me, Apr 21, 2007
    #10
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. valentin tihomirov

    Mixing comb and reg part in one process

    valentin tihomirov, Dec 31, 2003, in forum: VHDL
    Replies:
    7
    Views:
    624
    Oggie
    Jan 2, 2004
  2. Lloyd Sheen

    Mixing Server and Client Code

    Lloyd Sheen, Nov 18, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    391
    Dales
    Nov 18, 2003
  3. Jamie
    Replies:
    1
    Views:
    752
    Jamie
    Dec 5, 2003
  4. Rob
    Replies:
    0
    Views:
    425
  5. Replies:
    3
    Views:
    543
    Michael D. Ober
    Sep 30, 2006
Loading...

Share This Page