DennisWood
asked on
Why does stream not go on ?
In my file name.nam, i've saved the TagTp using my << operator, when i read the file out with my >> it returns me always only the first record.What should i do ??
Here's the code : ("name.nam" at end) :
#include<iostream>
#include<math.h>
#include<string>
#include<fstream.h>
#include "liste.h"
struct DatumTp { // Interner DatenTyp f?r Datum
unsigned short t, m; // Tag und Monat werden als Byte gespeichert
unsigned int j; // Jahr wird als integer gespeichert
};
class TagTp { // Klasse die den DatenSatzTyp darstellt
friend ostream & operator<<( ostream &, const TagTp & );
friend istream & operator>>( istream &, TagTp & );
public :
TagTp() { datum.t = 0;};
TagTp & operator=( const TagTp & );
DatumTp datum; // das Datum des eintrags
float start, ende, // Start und Endwert als float
min, max; // H?chst- und Tiefststand als float
bool isBlack(); // Gibt zur?ck ob die Candle schwarz ist
float bodySize(); // Gibt die Gr?áe des CandleBoddys zur?ck
bool operator>( TagTp); // Operator der festellt welches Datum ?lter
bool operator==( TagTp ); // zum Vergleich von zwei Tagen
};
ostream & operator<<( ostream &s, const TagTp & t ) {
return s<<":"<<t.datum.t<<"."<<t. datum.m<<" ."<<t.datu m.j<<"."
<<t.start<<t.ende<<t.max<< t.min;
}
istream & operator>>( istream &s, TagTp & t ) {
char c;
s >> c; // ":"
s >> t.datum.t;
s >> c; // "."
s >> t.datum.m;
s >> c; // "."
s >> t.datum.j;
s >> c; // "."
s >> t.start;
s >> t.ende;
s >> t.max;
s >> t.min;
return s;
}
int main() {
ifstream svF("name.nam");
TagTp rec;
char x;
svF >> rec;
while ( !svF.eof() ) {
svF >> rec;
cout << rec << endl;
cin >> x; // for waiting
}
}
Here is the file "name.nam" :
:23.8.99.11099.711299.8113 44.111088: 24.8.99.11 297.511283 .311404.91 1135.8:25. 8.99.11282 .411326114 28.911106. 3:26.8.99. 1132611198 .511393.51 1133.9:27. 8.99.11198 .511090.21 1295.31102 1.2:30.8.9 9.11087.71 0914.11117 6.610869.8 :31.8.99.1 0909.71082 9.311079.1 10725.4:1. 9.99.10828 .410937.91 1013.51078 4.3:2.9.99 .109241084 3.21092410 669.7:3.9. 99.10922.4 11078.5111 55.710922. 4:7.9.99.1 1079.11103 4.111191.8 10910.7:8. 9.99.11034 .111036.31 1164.91089 8.6:9.9.99 .11031.311 079.411172 .210900.8: 10.9.99.11 0.8711028. 411218.410 965.7:13.9 .99.11027. 411030.311 146.510886 .9:14.9.99 .11028.710 910.311061 10815.7:15 .9.99.1091 0.410801.4 1105010757 .4:16.9.99 .10795.810 737.510876 .510592.5: 17.9.99.10 745.410803 .610946.71 0690.6:20. 9.99.10801 .910823.91 0918.91071 5.9:21.9.9 9.10823105 98.5108231 0517.1:22. 9.99.10599 .410524.11 0688.41040 7.6:23.9.9 9.10524.11 0318.61064 3.810260.3 :24.9.99.1 0311.91027 9.310428.1 10128.6:27 .9.99.1027 9.310303.4 10498.7102 01.8:28.9. 99.10300.5 10275.5103 8610055.2: 29.9.99.10 274.310213 .510408.51 0119.8:30. 9.99.10214 .110337104 56.310155. 8:1.10.99. 10335.7102 .7310425.9 10108:4.10 .99.10274. 610401.210 538.310220 .4:5.10.99 .10401.210 400.610578 .210250.2: 6.10.99.10 399.810588 .310655.51 0340.8:7.1 0.99.10588 .310537106 87.110431: 8.10.99.10 534.510649 .810743.51 0423.7:11. 10.99.1064 9.810648.2 10781.2105 45.6:12.10 .99.10648. 810417.110 659.610366 .1:13.10.9 9.10412.31 0232.21049 5.910173.6 :14.10.99. 10230.9102 86.610416. 710071.6:1 5.10.99.10 286.610019 .710286.69 911.43:18. 10.99.1001 8.510116.3 10221.1988 4.2:19.10. 99.10117.5 10204.9104 1810093.8: 20.10.99.1 0203.31039 2.410485.1 10144.5:21 .10.99.103 90.710297. 710414.510 047.6:22.1 0.99.10581 .710470.21 0581.71030 1.2:25.10. 99.1046910 349.910518 .410225.8: 26.10.99.1 0350.91030 2.110486.4 10208.7:27 .10.99.103 02.810394. 910515.210 172.3:28.1 0.99.10397 .710622.51 0726.71039 7.7:29.10. 99.10629.2 10729.9108 83.110580. 1:1.11.99. 10730.8106 48.5108291 0568.1:2.1 1.99.10653 .710581.81 0816.11050 8.1:3.11.9 9.10582.51 0609.11075 9.210485.5 :4.11.99.1 0612.41063 9.61081810 523.4:5.11 .99.106401 0704.51088 5.510636.6 :8.11.99.1 0668.41071 8.810838.7 10546.7:9. 11.99.1071 5.110617.3 1080610506 .6:10.11.9 9.10611.91 0597.71071 310449.4:1 1.11.99.10 603.210595 .310716.71 0485.2:12. 11.99.1059 3.510769.3 10845.2105 13:15.11.9 9.10764.71 0760.81089 9.210626.8 :16.11.99. 10762.9109 32.310992. 910691.9
Here's the code : ("name.nam" at end) :
#include<iostream>
#include<math.h>
#include<string>
#include<fstream.h>
#include "liste.h"
struct DatumTp { // Interner DatenTyp f?r Datum
unsigned short t, m; // Tag und Monat werden als Byte gespeichert
unsigned int j; // Jahr wird als integer gespeichert
};
class TagTp { // Klasse die den DatenSatzTyp darstellt
friend ostream & operator<<( ostream &, const TagTp & );
friend istream & operator>>( istream &, TagTp & );
public :
TagTp() { datum.t = 0;};
TagTp & operator=( const TagTp & );
DatumTp datum; // das Datum des eintrags
float start, ende, // Start und Endwert als float
min, max; // H?chst- und Tiefststand als float
bool isBlack(); // Gibt zur?ck ob die Candle schwarz ist
float bodySize(); // Gibt die Gr?áe des CandleBoddys zur?ck
bool operator>( TagTp); // Operator der festellt welches Datum ?lter
bool operator==( TagTp ); // zum Vergleich von zwei Tagen
};
ostream & operator<<( ostream &s, const TagTp & t ) {
return s<<":"<<t.datum.t<<"."<<t.
<<t.start<<t.ende<<t.max<<
}
istream & operator>>( istream &s, TagTp & t ) {
char c;
s >> c; // ":"
s >> t.datum.t;
s >> c; // "."
s >> t.datum.m;
s >> c; // "."
s >> t.datum.j;
s >> c; // "."
s >> t.start;
s >> t.ende;
s >> t.max;
s >> t.min;
return s;
}
int main() {
ifstream svF("name.nam");
TagTp rec;
char x;
svF >> rec;
while ( !svF.eof() ) {
svF >> rec;
cout << rec << endl;
cin >> x; // for waiting
}
}
Here is the file "name.nam" :
:23.8.99.11099.711299.8113
ASKER
ok i'll try it
I found the problem. It's the floating point numbers. If you want to keep floating point numbers for start, ende, min, and max, then change the istream function in your source code to this:
istream & operator>>( istream &s, TagTp & t ) {
char c;
s >> c; // ":"
printf("1- C IS %c\n",c);
s >> t.datum.t;
s >> c; // "."
printf("2- C IS %c\n",c);
s >> t.datum.m;
s >> c; // "."
printf("3- C IS %c\n",c);
s >> t.datum.j;
s >> c; // "."
printf("4- C IS %c\n",c);
s >> t.start;
s >> c; // ":" we need to seperate with colons
s >> t.ende;
s >> c; // ":"
s >> t.max;
s >> c; // ":"
s >> t.min;
return s;
}
Then, change the format of your file to this:
:23.8.99.11099.0:711299.0: 811344.0:1 11088.0:24 .8.99.1129 7.0:511283 .0:311404. 0:911135.0 :8.0...... etc...
Note the added colons for the floating point numbers.
istream & operator>>( istream &s, TagTp & t ) {
char c;
s >> c; // ":"
printf("1- C IS %c\n",c);
s >> t.datum.t;
s >> c; // "."
printf("2- C IS %c\n",c);
s >> t.datum.m;
s >> c; // "."
printf("3- C IS %c\n",c);
s >> t.datum.j;
s >> c; // "."
printf("4- C IS %c\n",c);
s >> t.start;
s >> c; // ":" we need to seperate with colons
s >> t.ende;
s >> c; // ":"
s >> t.max;
s >> c; // ":"
s >> t.min;
return s;
}
Then, change the format of your file to this:
:23.8.99.11099.0:711299.0:
Note the added colons for the floating point numbers.
One more thing. It seems to me that you want to use colons to seperate your records.
If that is the case, leave your data file as is and change your start, ende, min, max
fields to int instead of float. Then you can still maintain your colon as the field
seperator. By the way, I actually compiled your source above, along with my
changes, and it did read all the records.
If that is the case, leave your data file as is and change your start, ende, min, max
fields to int instead of float. Then you can still maintain your colon as the field
seperator. By the way, I actually compiled your source above, along with my
changes, and it did read all the records.
brain, did you read the question history?
ASKER
Again much thanx for the extrem fast answers.
I don't really know who to give the points, but i think nietod answer was the first, so he got it. the problem where that i didn't have the seperators, cause i thaught, that floats have a fixed length.
I don't really know who to give the points, but i think nietod answer was the first, so he got it. the problem where that i didn't have the seperators, cause i thaught, that floats have a fixed length.
ASKER
nietod why don't you take the points ? Brain2000 has told the same.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
You are realy great, you saved my many hours desperation. Much thanx
Next time please split the points. I did take the time to actually compile and modify your source code until it worked on my end. So as nietod may have answered 10 minutes before me, I took more time to form my answer and provide you actual working source code.
Brain,
Please do not encourage the splitting of points! This is a major headache for the EE staff.
Next time I recommend you consider the code before trying to compile it. That can be a very innefficient way to find a solution and a working code example is often not as useful an answer as an explanation of the problem.
Please do not encourage the splitting of points! This is a major headache for the EE staff.
Next time I recommend you consider the code before trying to compile it. That can be a very innefficient way to find a solution and a working code example is often not as useful an answer as an explanation of the problem.
You must be right. After all, you have over 300,000 points in this area.
Fix that and see if it helps.