Mixing C and C++

I

Ian Collins

Salman said:
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.
 
V

Victor Bazarov

Salman said:
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
 
S

Salman

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?
 
V

Victor Bazarov

Salman said:
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
 
?

=?iso-8859-1?q?Erik_Wikstr=F6m?=

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?
 
M

masih12

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

#include <cstdio>
#include <iostream>

and you are good to go.


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?


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?

NO,IT IS NOT POSSIBLE TO MIX C,C++
 
M

Me

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...
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top