Dialogue 0001: Tedious Tasks in C++


My Own Meta-Analysis:

The following is a self-compiled list of algorithms that are very simple and intuitive in most languages, but turn out to be convoluted or quirky in C++. These top three examples were inspired by my own firsthand experiences, but if you are more experienced and would like to append a task, do tell.



| simplicio | I've been practicing C++ for a while, and I now want to discuss some things that are remarkably difficult to do in C++, relative to other languages...
| simplicio | 1. Knowing how much time a process takes (and getting the current time in general) is platform-dependent.
| salviati | Solution: use a third-party library like SDL2's GetPerformanceCounter().
| simplicio | 2. Reading the entire contents of a file as a string is pretty tedious...
| salviati | Solution: check out this blogpost.
| simplicio | 3. Formatting stuff when printing has a really weird syntax. Weird as hell.
| salviati | Solution: Start with this paper from the University of Michigan.
| salviati | One takeaway is: to mandate that a certain number of digits gets printed after the decimal point, try:
std::cout << std::fixed << std::setprecision(8) << number;
| simplicio | You must admit, it is counter-intuitive to be placing these modifiers to the right of the << operator.