Saturday 10 August 2019

Which alternative in C++?



One of the things about programming is that there are several ways to achieve the same goal. During my time coding in C++ I have noticed the following variations in ways to implement certain common features. My question is what are the advantages/disadvantages of each, I understand for the most part how each of them work, but I would like to know which is better in terms of performance, readability, and conformity to standards, as well as acceptability with OOP.



cout vs printf



cin vs scanf




endl vs \n



Thanks


Answer



if your primarily programming lang is C++ and you are doing object oriented programming, then it is going to be cout, cin and endl - hands down :)



it is not a matter of performance, but it is more of a matter of style and coherent coding.



in addition to that you get the perks of having cout, cin work on user defined types as well -- something that is not possible with printf scanf.



No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...