- 1
How do you guys output and input stuff?
I consider it as good style to have a blank line between my outputs, to improve readability in the console. So this is what I usually do: std::cout << "\n This is my first output. \n"; std::cout << "\n This is my second output \n"; Yes it's a bit of a pain to write \n twice for ever output but I feel like that's worth the effort for the user's convenience.
3 Antworten
+ 6
If it's about C++, use endl instead of \n. It would also be a good idea to add 'using namespace std' to simplify your lines.
#include <iostream>
using namespace std;
int main()
{
string something;
cout << "Demonstration of blank line in between prints" << endl << endl;
// 2 consecutive 'endl's.
cout << "Please insert something : ";
cin >> something;
cout << endl;
cout << "You inserted " << something << endl;
return 0;
}
+ 2
I know that you can use namespaces but our teacher told us not to it. On one hand you'll then never forget what namespaces everything is in, one the other hand there was a second reason which I unfortunately forgot...maybe stack overflow will say it 🤔
and I usuall use \n because it's shorter thand endl and it doesn't require to be separated by <<
+ 1
Also I usually ask for input like this:
std::string someString;
std::cout << "\n Please insert something! \n;
std::cout << "\n \t";
std::cin >> someString;
By using the tab it always visualized when the user is asked for input.
What do you guys think?
I hope that helps some new programmers to improve the readability of their output and input in the console! :)