Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Sep 23rd, 2005, 4:50 AM   #1
matko
Newbie
 
Join Date: Sep 2005
Posts: 28
Rep Power: 0 matko is on a distinguished road
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
matko is offline   Reply With Quote
Old Sep 23rd, 2005, 6:09 AM   #2
L7Sqr
Hobbyist Programmer
 
Join Date: Jun 2005
Location: here
Posts: 137
Rep Power: 0 L7Sqr is an unknown quantity at this point
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 you should get better results.
__________________
"...and though our kids are blessed their parents let them shoulder all the blame."
- The Quiet Things That No One Ever Knows [BrandNew]
L7Sqr is offline   Reply With Quote
Old Sep 23rd, 2005, 7:35 AM   #3
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
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
DaWei is offline   Reply With Quote
Old Sep 24th, 2005, 4:19 AM   #4
matko
Newbie
 
Join Date: Sep 2005
Posts: 28
Rep Power: 0 matko is on a distinguished road
Tank's its worrking!
cerr<<" \\";

Matko
matko is offline   Reply With Quote
Old Sep 25th, 2005, 5:35 PM   #5
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
Note that you should only use cerr for debugging, error messages, etc. cout is for output, cin for input, and cerr for error messages.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Sep 25th, 2005, 5:40 PM   #6
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
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
DaWei is offline   Reply With Quote
Old Sep 25th, 2005, 5:48 PM   #7
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
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.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Sep 25th, 2005, 7:31 PM   #8
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Quote:
By default, standard input is read from the keyboard, while standard output and standard error are printed to the screen. The freopen function can be used to redirect the streams to disk files or to other devices. The operating system allows you to redirect a program's standard input and output at the command level.
Quote:
Originally Posted by cerr
The object controls unbuffered insertions to the standard error output
Don't think I don't see you point, Ooble, because I do. Of course their names are meant to be mnemonic, and they are provided to ease their use for the purposes listed, and the clarity of the code could be affected.

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
DaWei is offline   Reply With Quote
Old Sep 26th, 2005, 2:08 PM   #9
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
OK, I see where you're coming from. Yeah, when I say "you should", I mean "it's recommended that". Happy? :p
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Sep 26th, 2005, 2:11 PM   #10
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
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
DaWei is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 12:36 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC