![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Sep 2005
Posts: 28
Rep Power: 0
![]() |
console output
how can i write text in just one line of console?
I'm trying to make process indicator with rotatiting '/' '|' '\' '-' signs in the center of console. I also have this problem: Can't compile this cout<<" \"; ERROR: New line in constant. How to override this? Matko |
|
|
|
|
|
#2 |
|
Hobbyist Programmer
Join Date: Jun 2005
Location: here
Posts: 137
Rep Power: 0
![]() |
To address the first issue:
You need to output a backspace character each time you want to 'rotate' the bar. I think the backspace is \b, but not sure. Notice that if you are not preforming any action other than spinning the bar output buffering will really screw with what you get, you will need to figure a way to 'not' buffer the output. The second problem is the fact that '\' is an escape character. Whatever follows it takes on special meaning (if any). In this case you are telling cout to output a '"' character which would normally terminate your string. Try cout << " \\";
__________________
"...and though our kids are blessed their parents let them shoulder all the blame." - The Quiet Things That No One Ever Knows [BrandNew] |
|
|
|
|
|
#3 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
You can set up your stream to be unbuffered. A quick way to see the influence on what you're trying is to use cerr instead of cout. It is unbuffered by default. With no buffering you don't have to call flush (or use endl).
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#4 |
|
Newbie
Join Date: Sep 2005
Posts: 28
Rep Power: 0
![]() |
Tank's its worrking!
cerr<<" \\"; Matko |
|
|
|
|
|
#5 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
Note that you should only use cerr for debugging, error messages, etc. cout is for output, cin for input, and cerr for error messages.
|
|
|
|
|
|
#6 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
Really? It's just an unbuffered stream, which one would want for errors, but I don't think it's written in stone anywhere. All these streams can be redirected (and their buffering altered, for that matter).
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#7 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
Of course. However, the main purpose of each is reflected in the name. It matters because other coders reading the code will expect to see output sent to the device using cout, and error messages using cerr.
|
|
|
|
|
|
#8 | ||
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
Quote:
Quote:
You will find, however, that I have a natural opposition to unilateral dicturms, as contrasted with suggestions. "...you should only use...", your words, are a dictum, but would better be phrased as a recommendation. I know people with more skill than I who deal in dictums. "You should only run your programs from the command line." Horse hockey.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
||
|
|
|
|
|
#9 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
OK, I see where you're coming from. Yeah, when I say "you should", I mean "it's recommended that". Happy? :p
|
|
|
|
|
|
#10 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
My problem wasn't with the "should", but with the "only" :p. Sure, I'm a happy camper
.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|