I was coding some C + code for a small hobbies project when I saw that I had a C-style operation I'm using IO Is C ++ projects considered "bad behavior" to include C Functions? What are the benefits of using currents on Si-style IO access? This is a hot topic. / P> Some people like to use C ++ IO because they are type-safe (you can not deviate between the type of object and type specified in the format string), and the rest with the rest Mode of C ++ flow of coding However, there are logic for C IO tasks (my personal favorite). Some of them are: Personally, I do not consider it bad practice to use the C stream in C ++ code. Even recommending using them on the C ++ stream. Will I consider the bad style to use both in the same project as others have mentioned, in a relatively larger project, you probably will not use them directly, but you can use one of the cover functions (or classes) Will use the set. , Which will be best for your coding criteria, and your needs (localization, type security, ...). You can use one or other IO interfaces to implement this high level interface, but you probably will only use one. Edit: Function function related to Instead of Consider translating this C ++ code: This can be really hard. With code (with a library to handle localization), with code printf , fopen , etc.).
printf function, the generated code is small (it can be important in the embedded environment).
localization of printf family. Please note that those information is only valid for some implementation. % instead of % m $ in the context of the reference, you can use it in the formatted string values Can be re-ordered. The following program on the standard program Hello World! will write.
#include & lt; Stdio.h & gt; Int main () {printf ("% 2 $ s% 1 $ s \ n", "World!", "Hello"); Return 0; }
if (nb_files_deleted == 1) stream & lt; & Lt; "A file"; Other streams & lt; & Lt; Nb_file_deleted & lt; & Lt; "Files"; Stream & lt; & Lt; The directory \ "was deleted from \" & lt; & Lt; Directory & lt; & Lt; "\" \ N ";
printf (ngettext ("A file deleted from directory \"% 2 $ s \ "", "% 1 $ d directory \ "% 2 $ s \" ", n), n, has been removed from dir;
Comments
Post a Comment