|
From: <h.r...@gm...> - 2002-07-08 16:58:52
|
> At 08.09 07/06/02 +0200, h.r...@gm... wrote:
> >...
> >At second:
> >In the following code is an error, but i cannot find it. Always if i type
> q
> >to finish the data entry i get a error message :
> >
> >testproj1.exe Fehler in Anwendung
> >Die Anweisung in "0x00401b21" verweist auf Speicher "0x00000000". Der
> >Vorgang "read konnte nicht auf dem Speicher durchgeführt werden...
> >
> >Codesnip:
> >
> >string SP(size_t n) {
> > string s(n, ' ');
> > return s;
> >}
> >
> >bool ReadDataKbd(const string &s) {
> > ofstream out(s.c_str());
> >
> > string ein;
> >
> > cout << "Sollwert:" << SP(6);
> > cin >> ein;
> > out << ein << endl;
> >
> > cout << "Untere Grenze: ";
> > cin >> ein;
> > out << ein << endl;
> >
> > cout << "Obere Grenze: ";
> > cin >> ein;
> > out << ein << endl;
> >
> > bool finished;
> > int cnt = 1;
> > size_t w = 5;
> >
> > do {
> > if (cnt > 99) w = 3;
> > else if (cnt > 9) w = 4;
> >
> > cout << "Messwert " << cnt << SP(w);
> > cin >> ein;
> > if (finished = (ein[0] == 'q')) break;
> > out << ein << endl;
> > cnt++;
> > } while (!finished);
> >
> > out.close();
> > return true;
> >}
> >
> >Thanks in advance
> >
> >greetings
> >Horst
>
>
> Hi,
>
> I've added the following function "main" to test your program:
>
> -------------
> int
> main()
> {
> ReadDataKbd("test.out");
> }
> ------------
>
> And found that the code works. i.e. I saw no extra output on the Dos box
> where I was running. My answers to the questions asked by your program
> were
>
> (sorry I could do no better since I do not understand the meaning of them
> :)
>
> Sollwert: aa
> Untere Grenze: bb
> Obere Grenze: cc
> Messwert 1 dd
> Messwert 2 ee
> Messwert 3 q
>
> and here is the output file
>
> test.out
> --------
> aa
> bb
> cc
> dd
> ee
> --------
>
> I use: Dev 4.9.3.0 (gcc 2.95) on Win98SE.
>
> --
> Luigi
> gi...@li...
>
thanks and sorry, but the error is on me, not in the code. I read some data,
try to calculate with it, but dont store them. The calculation function has
no data and gives the error. The correct function is:
string SP(size_t n) {
string s(n, ' ');
return s;
}
bool ReadDataKbd(const string &s) {
ofstream out(s.c_str());
string ein;
cout << "Sollwert:" << SP(6);
cin >> ein;
out << ein << endl;
cout << "Untere Grenze: ";
cin >> ein;
out << ein << endl;
cout << "Obere Grenze: ";
cin >> ein;
out << ein << endl;
bool finished;
int cnt = 1;
size_t w = 5;
do {
if (cnt > 99) w = 3;
else if (cnt > 9) w = 4;
cout << "Messwert " << cnt << SP(w);
cin >> ein;
if (finished = (ein[0] == 'q')) break;
out << ein << endl;
cnt++;
} while (!finished);
out.close();
return true;
}
and again, sorry for my stupid question
greetings
Horst
--
GMX - Die Kommunikationsplattform im Internet.
http://www.gmx.net
|