Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Mixing C and C++

Reply
Thread Tools

Mixing C and C++

 
 
Salman
Guest
Posts: n/a
 
      04-17-2007
How to mix C and C++ ?

 
Reply With Quote
 
 
 
 
Ian Collins
Guest
Posts: n/a
 
      04-17-2007
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.
 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      04-17-2007
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


 
Reply With Quote
 
Salman
Guest
Posts: n/a
 
      04-17-2007
On Apr 18, 4:14 am, "Victor Bazarov" <(E-Mail Removed)> 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?

 
Reply With Quote
 
Victor Bazarov
Guest
Posts: n/a
 
      04-18-2007
Salman wrote:
> On Apr 18, 4:14 am, "Victor Bazarov" <(E-Mail Removed)> 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


 
Reply With Quote
 
c-winer@hotmail.com
Guest
Posts: n/a
 
      04-18-2007
On Apr 17, 6:06 pm, Salman <(E-Mail Removed)> 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.

http://www.velocityreviews.com/forums/(E-Mail Removed)

 
Reply With Quote
 
=?iso-8859-1?q?Erik_Wikstr=F6m?=
Guest
Posts: n/a
 
      04-18-2007
On 18 Apr, 01:54, Salman <(E-Mail Removed)> wrote:
> On Apr 18, 4:14 am, "Victor Bazarov" <(E-Mail Removed)> 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

 
Reply With Quote
 
masih12@gmail.com
Guest
Posts: n/a
 
      04-18-2007
On Apr 17, 11:19 pm, Erik Wikström <(E-Mail Removed)> wrote:
> On 18 Apr, 01:54, Salman <(E-Mail Removed)> wrote:
>
> > On Apr 18, 4:14 am, "Victor Bazarov" <(E-Mail Removed)> 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++

 
Reply With Quote
 
Ian Collins
Guest
Posts: n/a
 
      04-18-2007
(E-Mail Removed) wrote:
>
> NO,IT IS NOT POSSIBLE TO MIX C,C++
>

Nonsense.

--
Ian Collins.
 
Reply With Quote
 
Me
Guest
Posts: n/a
 
      04-20-2007
On Tue, 17 Apr 2007 16:54:24 -0700, Noone wrote:

> On Apr 18, 4:14 am, "Victor Bazarov" <(E-Mail Removed)> 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...
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Mixing and matching VB and C# in vs.net 2005 jason@cyberpine.com ASP .Net 3 09-30-2006 02:51 AM
mixing pix-to-pix vpn and pptp-dial-in-vpn on pix501 Tom Cisco 4 11-17-2004 02:18 PM
Mixing Workgroup and Domain PC's Lee Wireless Networking 2 11-01-2004 09:04 PM
3750's mixing EMI and SMI Brian V Cisco 5 02-11-2004 04:25 PM
Mixing comb and reg part in one process valentin tihomirov VHDL 7 01-02-2004 05:03 PM



Advertisments