4 ms·
Looking at the Getting Started section... Is this really the best way to write text out to the console in C++, or is it just traditional? cout << "Hello Wo
by russellbeattie 9y ago
Looking at the Getting Started section... Is this really the best way to write text out to the console in C++, or is it just traditional?
cout << "Hello World!" << endl;
It seems like something a bit simpler, readable and predictable would be better for beginners and/or experienced devs alike. I look at that and wonder where did cout come from? Is << a heredoc or some sort of pipe indirection, or am I bit-shifting? And is endl a keyword? Does it always follow cout? Is this like a Pascal endif? Oh, it's basically just a newline. What's wrong with just "\n"? I think C++ devs purposefully make their language as obtuse as possible.
Maybe NOT starting with streamio and operator overloading might be a more modern way to start teaching the language?
- louiz 9y ago> I look at that and wonder where did cout come from? This is the biggest issue with this. STOP TEACHING “using namespace std;”. This is bad, bad, bad, and it sucks.
- chrisseaton 9y ago> Oh, it's basically just a newline. What's wrong with just "\n"? Not all platforms use “\n” for a new line.
- deleted 9y ago[deleted]
- gpderetta 9y agoThe std::stream will translate '\n' to what's required for the underlying platform, so it is a perfectly portable way to terminate a line. What std::endl really does is flush the internal stream buffer if any.
- johannes1234321 9y agoFor beginners I didn't have trouble with `cout` and `<<`. Just teach that that's how you print without going in details. This is more a problem with folks with experience in other languages, who know bitshift or heredoc syntax. But those can be teached in a more advanced way.
- detaro 9y agoAnecdotally, beginners have less issues with this than trying to remember printf format strings.