473,404 Members | 2,137 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

Can this be done with cout ?

#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
16 3948
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
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
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
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
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


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


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
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
>> 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
by: qazmlp | last post by:
I hope comp.lang.c will not find the following question as a complete off-topic. I would like to remove ie.comment out the 'cout' statements during compilation(actually preprocessing) time. ...
10
by: da Vinci | last post by:
Hello. First off, I am not sure of the exact jargon used, so I will ask a question regarding it. Then on to my other question. When you use things like cout and cin from the iostream header...
7
by: mead | last post by:
The code is from a Meyers' book... class BankAccount { ... }; // as above // new class representing accounts that bear interest class InterestBearingAccount: public BankAccount { public:...
6
by: Omid | last post by:
Hi. I have problems when I try to redirect everything that is sent to cout to a file. I have one piece of code that works and one that does not work. The only difference is which headers I use....
5
by: Mastupristi | last post by:
I want to obtain the c++ equivalent of: unsigned short us = 347; printf("0x%04hX",us); that outputs "0x015B" I ried with: cout.setf(ios_base::hex,ios_base::basefield);
10
by: Gurikar | last post by:
How to make cout not printing on the console. i mean void main() { cout<<"Hello world"<<endl; } Is there any way where i can block printing on console even when iam
7
by: Joe C | last post by:
I'd like to have better control of text output to the console. I'm using Windows and have a little (non-standard) function to help me out: #include <windows.h> void locate(int x, int y ) {...
5
by: Jintty | last post by:
Hi, I'm trying to write a program that will read a txt file, copy it into another text file and display the number of words, lines and paragraphs. I was able to get the copying portion done, but...
1
by: wishbone34 | last post by:
Below is a postfix eval. program i have made, it works fine, however my professor wants me to make a header file with the class, and I tried this class StackType { public: void...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.