Can this be done with cout ?

M

mrDumbass

#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
?
 
V

Victor Bazarov

mrDumbass said:
#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
 
M

mrDumbass

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?
 
V

Victor Bazarov

mrDumbass said:
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"?
 
L

Larry I Smith

mrDumbass said:
#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);
}
 
N

nooneinparticular

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?
 
M

mrDumbass

(e-mail address removed) schreef:
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
 
V

Victor Bazarov

mrDumbass said:
(e-mail address removed) schreef:



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
 
M

mrDumbass

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

sorry to all for my off-topic question
 
J

Jonathan Mcdougall

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
 
L

Larry I Smith

Jonathan said:
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
 
J

Jonathan Mcdougall

tnx! Larry, system("cls") does the trick.
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
 
S

Son of Sam

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.
 
D

Dietmar Kuehl

Larry said:
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.
 
M

mrDumbass

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");
 
K

Karl Heinz Buchegger

mrDumbass said:
Son of Sam schreef:

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.
 
J

Jonathan Mcdougall

Even if he only wnats to use this program on a win32 pc, system()
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top