|
From: Luigi S. <gi...@li...> - 2002-07-08 03:52:33
|
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=FChrt 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 =3D 1;
> size_t w =3D 5;
>
> do {
> if (cnt > 99) w =3D 3;
> else if (cnt > 9) w =3D 4;
>
> cout << "Messwert " << cnt << SP(w);
> cin >> ein;
> if (finished =3D (ein[0] =3D=3D '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=20
where I was running. My answers to the questions asked by your program were=
=20
(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...
|