Guest Gnome Chomsky Posted August 29, 2013 Share Posted August 29, 2013 I'm fairly new to C++ but I have experience in C. I asked some people and they don't know so I thought I'd post the question on here. Is there a way to print multiple line breaks without putting cout << endl << endl << endl << endl etc etc etc? I know you can do cout << "\n\n\n\n\n etc etc etc" but I prefer endl over "\n". I tried cout << 5endl and cout << endl*5 but neither of those worked. Is it tacky stylistically to put a bunch of endl's? I like a lot of space in my programs. Link to comment Share on other sites More sharing options...
TakeruK Posted August 30, 2013 Share Posted August 30, 2013 I'm not an expert on C++. Like you, I know C and I have used a bit of C++ only. But here are my thoughts: Having a bunch of blank spaces in your output sounds like a good idea to me. Sometimes I also use "***********" or "----------------" strings to help me see different sections. I don't think stuff like endl*5 would work because endl is probably encoded as some unicode value or something and multiplying that value by 5 might result in something undesired? I think your best bet, for simple code, is cout << "\n\n\n\n\n" I'm not sure what you mean by saying you prefer endl over \n. When I looked up the difference, I see that the only difference between endl and \n (new line) is that endl will flush a buffered stream. cout is not a buffered stream, so the behaviour of endl and \n is going to be the same in this case? Unless you mean you prefer reading/writing code with "endl" instead of "\n". If so, that's fine but I would point out that "\n" is something used in many different languages while I have not seen "endl" in many other places than C++ (I'm sure it exists, but I feel that "\n" is the standard "new line" character). Link to comment Share on other sites More sharing options...
MikKar Posted September 10, 2013 Share Posted September 10, 2013 (edited) C++ isn't really the language for doing text manipulation and the like. endl or "\n" is the best thing you can use, otherwise if that is a possibility for you, using regular expressions instead of C++ as they'll probably be much more efficient to do that sort of thing. There are different schools with regards to what is better between endl or "\n", my personal *preference* is to stick to the basic STL and go with std::endl. For (elaborate) text manipulation I prefer using sed if I am on Linux/Unix. Edited September 10, 2013 by MikKar Link to comment Share on other sites More sharing options...
gnufoo Posted September 13, 2013 Share Posted September 13, 2013 #include <iostream> using namespace std; int main() { int numberOfNewLines = 5; for(int i = 0; i < numberOfNewLines; i++) cout << endl; } Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now