std::endl vs. "\n" I refer you to the "C++ Core Guidelines", section SL.50: "Avoid endl".| Reason The endl manipulator is mostly equivalent to '\\n' and "\\n"; as most commonly used it simply slows down output by doing redundant flush()s. This slowdown can be significant compared to printf-style output. Example
Note For cin/cout (and equivalent) interaction, there is no reason to flush; that's done automatically. For writing to a file, there is rarely a need to flush. Note Apart from the (occasionally important) issue of performance, the choice between "\\n" and endl is almost completely aestetic. |
"yes" and "ceramic". The reason this is a bad idea is that happens when the user types in some combination you didn't have in your code? Answer: the code breaks. So the solution is to restrict the input to one char, use the std::toupper function on it, then you only have one test: 'C' for ceramic say. If there are multiple things you want to select from, then use a switch statement. |
|
std::left and std::right. There are lots of these associated with the iostream header alone, never mind any thing else one might include.std:: everywhere, then you don't have to do anything to it to make it work.std::, so if you learn to do that now, you will be ahead of the game.| theLoneWolf wrote: |
|---|
| I know "\n" but what is "\\n"? Are they the same? |
| Thanks! But I know "\n" but what is "\\n"? Are they the same? |
|
|