Yuki
Yuki

Reputation: 11

When opening a file, C or C++?

Currently I'm using C++ for a program I'm writing and I have an, a query regarding Old v New.

Looking online I see people using the C++ syntax to open files. I'm moving to C++ so I should keep up with the times however it occurs to me is it better using the C way or the latter? I'm taking into consideration:

Thank you.

Upvotes: 1

Views: 133

Answers (2)

Alexey Frunze
Alexey Frunze

Reputation: 62048

Neither plain C nor plain C++ gives you access to security features of the OS. In Windows and Linux/UNIX there are file system related security features and you have to use them in order to set or query file access rights.

Whether you're writing in C or in C++, security remains your responsibility. Neither of the languages frees you from things like input validation and error checks.

File I/O speed should be about the same on the same platform with the same compiler, unless you use different buffering modes or different sizes of buffers. The same should be true for the amount of memory used implicitly in the file I/O functions.

If you're writing in C++, you should generally use C++ I/O functions, unless there's something you can't do with them (e.g. you can't access OS-specific functionality and therefore are forced to use plain C functions provided by your OS).

Upvotes: 3

us2012
us2012

Reputation: 16253

Use the functionality that the C++ standard library provides you. If, and only if, you run into problems with speed or memory, start profiling and exploring other options.

Upvotes: 2

Related Questions