Connecting Tech Pros Worldwide Help | Site Map

C or C++

Member
 
Join Date: Jul 2007
Location: Philippines
Posts: 54
#1: Aug 30 '08
What is better for a file manipulation? C or C++ ?
Ganon11's Avatar
Moderator
 
Join Date: Oct 2006
Location: New York, United States of America
Posts: 3,428
#2: Aug 30 '08

re: C or C++


Both will work equally well. I tend to think C++ is easier to use, as it puts all the file manipulation I've needed into handy classes like ifstream and ofstream. However, using this could be overkill depending on exactly what you want to do.

C will also work, but you'll have to mess with FILE*s and strange functions.

It's up to you, really.
Member
 
Join Date: Aug 2008
Location: South essex, England
Posts: 82
#3: Aug 30 '08

re: C or C++


I dont have any expierence of c, but I think the c++ method is easy, and not to worry about.
Moderator
 
Join Date: Mar 2007
Location: North Bend Washington USA
Posts: 5,366
#4: Aug 30 '08

re: C or C++


Most C++ library implementations use a FILE* deep down in there.

So your answer is: C and C++ use the same I/O. The only difference is C++ has written a lot of the code to manage a FILE* for you (those are your C++ streams). Of course, you can always reinvent the wheel and keep recoding I/O using FILE*. Using a FILE* directlt is just a question of a) adding development cost, b) adding maintenance costs, c) having code that can't integrate easily into other programs, d)etc...
Member
 
Join Date: Jul 2007
Location: Philippines
Posts: 54
#5: Sep 2 '08

re: C or C++


with your replies i think i should use C++.Thanks guys...
Banfa's Avatar
AdministratorVoR
 
Join Date: Feb 2006
Location: South West UK
Posts: 6,161
#6: Sep 2 '08

re: C or C++


Since anything C can do C++ can do and vice-versa this question really boils down to in any (programming) situation should I use C or C++.

The answer is going to be all things being equal (i.e. there is both C and C++ compilers available for you platform) then you should always choose C++.

C++ was invented after C in the knowledge of all the problems with the C programming language and has tried to address those problems as well as introducing classes and other features to add object orientated programming.

If used properly a lot more powerful and avoids some of the pitfalls of C (it does of course create its own but they are a little harder to fall into).

C++ should be your default choice in an situation unless you can write down a really good reason why you have to use C.
Reply