By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,129 Members | 1,331 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,129 IT Pros & Developers. It's quick & easy.

Can this be done with cout ?

P: n/a
#include <iostream>
#include <algorithm>
#include <string>
#include <fstream>

using namespace std;

/*
i would like to keep the numbers of the output : Power , step etc,
on the same place in the console. But this isnt going to work with
this code... So the idea is that the numbers behind the '=' signs
change
without going down in the console. how do i do this ?
*/

int main()
{
int dummie;
cout << "Power = 45\n";
cout << "Step = 1\n";
cout << "Magnitude = 34\n";
cout << "press a digit";
scanf("%d",&dummie); // press key..
cout << "\r\r\r\rPower = 48\n"; // going back to first line and
overwrite it.
cout << "Step = 2\n"; // overwrite second line with new data.
cout << "Magnitude = 29\n"; // overwrite last line with new data.
cout << "press a digit";
scanf("%d",&dummie); // press key..
return(1);
} // well this doesnt work but how do i change the code to make it work
?

Jul 23 '05 #1
Share this Question
Share on Google+
16 Replies


P: n/a
mrDumbass wrote:
#include <iostream>
#include <algorithm>
#include <string>
#include <fstream>

using namespace std;

/*
i would like to keep the numbers of the output : Power , step etc,
on the same place in the console. But this isnt going to work with
this code... So the idea is that the numbers behind the '=' signs
change
without going down in the console. how do i do this ?
There is no way in the Standard C++. Anything available would be
platform-specific. See 'curses' library or 'ANSI terminal strings'
or anything else of that nature.
*/


V
Jul 23 '05 #2

P: n/a
So it is in my case dependend on the options of my DEV-C++ terminal
if it is possible and how to make it so?

Jul 23 '05 #3

P: n/a
mrDumbass wrote:
So it is in my case dependend on the options of my DEV-C++ terminal
if it is possible and how to make it so?


I don't understand the question. What's "DEV-C++ terminal"?
Jul 23 '05 #4

P: n/a
mrDumbass wrote:
#include <iostream>
#include <algorithm>
#include <string>
#include <fstream>

using namespace std;

/*
i would like to keep the numbers of the output : Power , step etc,
on the same place in the console. But this isnt going to work with
this code... So the idea is that the numbers behind the '=' signs
change
without going down in the console. how do i do this ?
*/

int main()
{
int dummie;
cout << "Power = 45\n";
cout << "Step = 1\n";
cout << "Magnitude = 34\n";
cout << "press a digit";
scanf("%d",&dummie); // press key..
cout << "\r\r\r\rPower = 48\n"; // going back to first line and
overwrite it.
cout << "Step = 2\n"; // overwrite second line with new data.
cout << "Magnitude = 29\n"; // overwrite last line with new data.
cout << "press a digit";
scanf("%d",&dummie); // press key..
return(1);
} // well this doesnt work but how do i change the code to make it work
?


#include <iostream>
#include <cstdlib>

using namespace std;

int main()
{
char dummie;

// unix/linux clear the screen.
// use system("cls"); on MS Windows
system("clear");

// display text starting at top line of screen
cout << "Power = 45\n";
cout << "Step = 1\n";
cout << "Magnitude = 34\n";

cout << "press a key then Enter ";
// won't work as expected if more than one key pending
cin >> dummie; // read keypress

// unix/linux clear the screen.
// use system("cls"); on MS Windows
system("clear");

// display text starting at top line of screen
cout << "Power = 48\n";
cout << "Step = 2\n";
cout << "Magnitude = 29\n";

cout << "press a key then Enter ";
// won't work as expected if more than one key pending
cin >> dummie; // read keypress

return(1);
}
Jul 23 '05 #5

P: n/a
On Mon, 11 Jul 2005 15:28:48 -0400, Victor Bazarov
<v.********@comAcast.net> wrote:
mrDumbass wrote:
So it is in my case dependend on the options of my DEV-C++ terminal
if it is possible and how to make it so?


I don't understand the question. What's "DEV-C++ terminal"?


I would assume that he is using Dev-C++ as his IDE - writing terminal
(non-windows) applications. It's what I use - Am I correct?
Jul 23 '05 #6

P: n/a


no***************@nowhere.net schreef:
On Mon, 11 Jul 2005 15:28:48 -0400, Victor Bazarov
<v.********@comAcast.net> wrote:
mrDumbass wrote:
So it is in my case dependend on the options of my DEV-C++ terminal
if it is possible and how to make it so?


I don't understand the question. What's "DEV-C++ terminal"?


I would assume that he is using Dev-C++ as his IDE - writing terminal
(non-windows) applications. It's what I use - Am I correct?


Ehm yes i use Bloodshed Dev-C++ as my IDE.(iam a total idiot, keep this
in mind)
i just compile my code with it and press 'run' to run it

Jul 23 '05 #7

P: n/a
mrDumbass wrote:
no***************@nowhere.net schreef:
On Mon, 11 Jul 2005 15:28:48 -0400, Victor Bazarov
<v.********@comAcast.net> wrote:

mrDumbass wrote:

So it is in my case dependend on the options of my DEV-C++ terminal
if it is possible and how to make it so?

I don't understand the question. What's "DEV-C++ terminal"?


I would assume that he is using Dev-C++ as his IDE - writing terminal
(non-windows) applications. It's what I use - Am I correct?

Ehm yes i use Bloodshed Dev-C++ as my IDE.(iam a total idiot, keep this
in mind)
i just compile my code with it and press 'run' to run it


This newsgroup discusses standard C++ language, not Dev-C++ nor any other
IDE, nor anything pertaining to any particular terminals. Your question
cannot be answered without going into specifics of platform-dependent
behaviour. Please for questions of that nature find a newsgroup that
deals with your platform or your compiler.

V
Jul 23 '05 #8

P: n/a
tnx! Larry, system("cls") does the trick.
such an simple solution for my problem

sorry to all for my off-topic question

Jul 23 '05 #9

P: n/a
> tnx! Larry, system("cls") does the trick.
such an simple solution for my problem

sorry to all for my off-topic question


Bear in mind that this is not portable. On one of the systems I use,
system("cls") executes the spreadsheet program and then deletes all my
emails. Happened to me twice. Dang.
Jonathan

Jul 23 '05 #10

P: n/a
Jonathan Mcdougall wrote:
tnx! Larry, system("cls") does the trick.
such an simple solution for my problem

sorry to all for my off-topic question


Bear in mind that this is not portable. On one of the systems I use,
system("cls") executes the spreadsheet program and then deletes all my
emails. Happened to me twice. Dang.
Jonathan


Sounds like a virus infected machine to me.

On Windows, "cls" clears the screen, any other action
means something is terribly wrong.

Larry
Jul 23 '05 #11

P: n/a
> >>tnx! Larry, system("cls") does the trick.
such an simple solution for my problem sorry to all for my off-topic question
Bear in mind that this is not portable. On one of the systems I use,
system("cls") executes the spreadsheet program and then deletes all my
emails. Happened to me twice. Dang.
Sounds like a virus infected machine to me. On Windows, "cls" clears the screen, any other action
means something is terribly wrong.


It was a joke, except for the portability part.

Jonathan

Jul 23 '05 #12

P: n/a
Even if he only wnats to use this program on a win32 pc, system()
commands can be very dangerous and should be avoided in certain cases.
Why do you return(1) has this a reason?
return(0) more common when your porogram finishes without an error.

Jul 23 '05 #13

P: n/a
Larry I Smith wrote:
Sounds like a virus infected machine to me.
Does it? I don't think so.
On Windows, "cls" clears the screen, any other action
means something is terribly wrong.


Strangely enough, I rarely work on Windows machines and cls may
mean rather different things (ranging from nothing at all to really
weird stuff). The point is that 'system("cls")' is platform specific
and may work as intended on some systems but doing weird stuff on
others.
--
<mailto:di***********@yahoo.com> <http://www.dietmar-kuehl.de/>
<http://www.eai-systems.com> - Efficient Artificial Intelligence
Jul 23 '05 #14

P: n/a


Son of Sam schreef:
Even if he only wnats to use this program on a win32 pc, system()
commands can be very dangerous and should be avoided in certain cases.
Why do you return(1) has this a reason?
return(0) more common when your porogram finishes without an error.


the return(1) is a mistake
i get the impression that a system-command can be somewhat tricky
if used under the wrong platvorm. Can i do a check if the program is
running under windows?

something like :
if (system.platvorm == win32)
system("cls");

Jul 23 '05 #15

P: n/a
mrDumbass wrote:

Son of Sam schreef:
Even if he only wnats to use this program on a win32 pc, system()
commands can be very dangerous and should be avoided in certain cases.
Why do you return(1) has this a reason?
return(0) more common when your porogram finishes without an error.


the return(1) is a mistake
i get the impression that a system-command can be somewhat tricky
if used under the wrong platvorm. Can i do a check if the program is
running under windows?

something like :
if (system.platvorm == win32)
system("cls");


You mean in the executable?
No. And you don't need it. Typically a program compiled on
platform A won't run on platform B at all for various resons.

But you may check your compiler documentation. Usually there are special
macros defined which can be used to diagnose a wrong compiling platform.

--
Karl Heinz Buchegger
kb******@gascad.at
Jul 23 '05 #16

P: n/a
>> Even if he only wnats to use this program on a win32 pc, system()
commands can be very dangerous and should be avoided in certain cases.
Why do you return(1) has this a reason?
return(0) more common when your porogram finishes without an error.
i get the impression that a system-command can be somewhat tricky
if used under the wrong platvorm.
Yes, that the essence of non-portable calls.
Can i do a check if the program is
running under windows?

something like :
if (system.platvorm == win32)
system("cls");


and else... what? You see the problem? You cannot possibly list all
systems with all commands. You can either: 1) stick to standard
features; 2) use portable, 3rd party librairies (such as ncurses); 3)
have a compile-time switch (like you're proposing) listing a few major
systems; 4) stick to one system with non-portable calls. I'd go for
number 2.

If you want to do number 3, check for each compiler, they usually
#define a name, such as WIN32.

Jonathan

Jul 23 '05 #17

This discussion thread is closed

Replies have been disabled for this discussion.