[Console] How do I return to a previous line?
Author |
Message |
Cancer Sol
|
Posted: Mon Apr 29, 2013 8:52 pm Post subject: [Console] How do I return to a previous line? |
|
|
I've tried to look up all the different ways to return to a previous line, and don't tell me to use a loop because that's not what I need.
I'm trying make a delete/erase line function, and I've tried doing this before:
c++: |
void deleteline()
{
cout << "\r \r\b"; //I thought a backspace would have the cursor return to the previous line
}
|
But it didn't work out like I thought it would, unfortunately.
So how can I do something like this?
Also, kinda a newb question, but, should I code like this:
c++: |
/* What I do all the time */
cout << "1. Do stuff\n"
<< "2. Do other stuff\n"
<< "3. Do more stuff\n";
|
Or this:
c++: |
/* What I sometimes see on the internet */
cout << "1. Do stuff\n2. Do other stuff\n3. Do more stuff\n";
|
I do the first way because it just looks easier to read, but it's just my opinion.
Is it better to the second way because it's shortened? |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Insectoid
|
Posted: Tue Apr 30, 2013 5:06 am Post subject: RE:[Console] How do I return to a previous line? |
|
|
As for your first question, you can't. Not without using complicated platform-dependant libraries that you certainly aren't ready for.
And for your second question, do whichever you prefer. Doesn't really matter. |
|
|
|
|
|
DemonWasp
|
Posted: Tue Apr 30, 2013 5:19 am Post subject: RE:[Console] How do I return to a previous line? |
|
|
Insectoid is right about your first question.
For your second, I would suggest:
code: |
cout << "1. Do stuff\n";
cout << "2. Do other stuff\n";
cout << "3. Do more stuff\n";
|
Or:
code: |
cout << "1. Do stuff" << endl;
cout << "2. Do other stuff" << endl;
cout << "3. Do more stuff" << endl;
|
The latter will force the 'cout' stream to flush every time 'endl' is appended.
Although you can string together the stream operator like you have in that example, I generally prefer one statement per line (especially in C++, where compilers and IDEs aren't great at telling you the exact location of syntax errors). |
|
|
|
|
|
Cancer Sol
|
Posted: Tue Apr 30, 2013 11:38 am Post subject: Re: [Console] How do I return to a previous line? |
|
|
Thanks guys.
For my console application, I think I'll just stick with clearing the screen for now, even if it makes flashes I don't like. |
|
|
|
|
|
|
|