www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/01/05/02:34:42

From: authentic AT tip DOT nl (Rick)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Several questions on data input and checking
Date: Sun, 04 Jan 1998 07:03:53 GMT
Organization: NL-NIC
Lines: 149
Message-ID: <68q0m1$lnq$2@cadmium.aware.nl>
References: <34ada35b DOT 324349151 AT news DOT netins DOT net>
Reply-To: authentic AT tip DOT nl
NNTP-Posting-Host: nijmegen-021.std.pop.tip.nl
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Hallo Paul,

Whats wrong with conio && iostreams ???
Anyway to answer the original question I digged up an
old  code which I made for MS C. Although I think
for djgpp you have built in functions for text mode too...
Please fill me in on these details..

Rick


Hello however you are(would be nice to sign with a name..),

IOstreams are a general source of trouble while learning c++.
I remember that what I did was printing out all streambuf related
functions, and made a try out program for all those functions
like rdbuf->in_available etc. It sure helped me understand
the basics(although I seldomly use them in fact).

Anyway ALL of what you are describing has to do with the buffered
character of the streams. A stream is not automatically flushed after
operations. However ENDL flushes cout after it put the newline in.

Another thing is that EVERY stream can go wrong in more then one way.
For instance a filestream may reach EOF, or, as in your case,
a cin might read wrong data. In that cases cin is given a null, while
also there are some streambuf flags set(in fact the fail/bad bits).
Thats why you so often read things like:
char c;
while (cin>>c){
	//proces chars
	}


damnulp AT netins DOT net (DamnULP) wrote:



>The usual "I'm new to C++" statements here....

>I'm working on a program that requires a bit of input from the user:

>while (ge<0 | ge>1000)
>{
>gotoxy(10,4);  cout<<"What is the germanium concentration (in g/l)?\n";
>gotoxy(70,4);  cin>>ge;
>}

>This works fine until someone enterssomething like a "w".  Then it goes
>into an loop that can only be exited by the ctrl-brk key.  Is there a way
>to check for this and stop the loop from starting?

>Also, after several more of these loops asking for other data, I ask for a
>line of comments, viz:

>gotoxy(10,15); cout <<"Please enter any other relevent comments....\n";
>gotoxy(15,16); cin.getline(comm,65);

>this gets skipped each time and the comments array is blank.  The same type
>of statements work fine earlier in the program.  Any ideas why it works
>before the cin statements but not after?

>tia for any help.

>---

>DamnULP

code begins:
#include <dos.h>
#include <iostream.h>
#include <iomanip.h>

//using BIOS interrupts inside gcc

union REGS regs;
//predefined union with dwordregs as .d ,
//wordregisters as .w and byte regs as .h

void cls_all_screens(){
     //does not return
     //since both bios functions does not
     //return carry flag or error
         regs.h.ah=0x0f;
         int86(0x10,&regs,&regs);

         regs.h.ah=0x00;
         int86(0x10,&regs,&regs);

}
int getxy(){
         //get the cursorpos
        regs.h.ah=0x03;
        int86(0x10,&regs,&regs);
        return regs.w.dx;
}
void clear_line_all_screens(int x){
         regs.h.ah=0x06;
         regs.h.al=0x01;
         regs.h.bh=0x07;
         regs.h.ch=x;
         regs.h.cl=0;
         regs.h.dh=++x;
         regs.h.dl=0x50;
         int86(0x10,&regs,&regs);
}
void gotoxy(int x, int y){
        //set the cursor on page 0
        regs.h.ah=0x02;
        regs.h.bh=0;
        regs.h.dh=x;
        regs.h.dl=y;
        int86(0x10,&regs,&regs);
}

void get_key(){
     regs.h.ah=0x1;
     int86(0x16,&regs,&regs);
     regs.h.ah=0x00;
     int86(0x16,&regs,&regs);
}


void main()
{
        unsigned char errs;
        cout     << "Message on screen!"<<nl
                 << "Press key for clearing"<<endl;
        get_key();
        //clear total screen
        cls_all_screens();
        get_key();

        for (int i=0;i< 3;i++){
            cout  << "Press a key for next cursorreplacement"<< endl;
            get_key();
            clear_line_all_screens(i+1);
            gotoxy(i+1,i*10);          //goto some random position
            int xy=getxy();            //display position
            cout     << "Cursor line : "<< (xy>>8) << ",   "
  	             << "Cursor row  : "<< (xy&0xff)<< endl;
        }
        cout<< "Press a key to return to a clean screen"<<endl;
        get_key();
        cls_all_screens();
}



- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019