Link to home
Start Free TrialLog in
Avatar of DennisWood
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.datum.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.811344.111088:24.8.99.11297.511283.311404.911135.8:25.8.99.11282.41132611428.911106.3:26.8.99.1132611198.511393.511133.9:27.8.99.11198.511090.211295.311021.2:30.8.99.11087.710914.111176.610869.8:31.8.99.10909.710829.311079.110725.4:1.9.99.10828.410937.911013.510784.3:2.9.99.1092410843.21092410669.7:3.9.99.10922.411078.511155.710922.4:7.9.99.11079.111034.111191.810910.7:8.9.99.11034.111036.311164.910898.6:9.9.99.11031.311079.411172.210900.8:10.9.99.110.8711028.411218.410965.7:13.9.99.11027.411030.311146.510886.9:14.9.99.11028.710910.31106110815.7:15.9.99.10910.410801.41105010757.4:16.9.99.10795.810737.510876.510592.5:17.9.99.10745.410803.610946.710690.6:20.9.99.10801.910823.910918.910715.9:21.9.99.1082310598.51082310517.1:22.9.99.10599.410524.110688.410407.6:23.9.99.10524.110318.610643.810260.3:24.9.99.10311.910279.310428.110128.6:27.9.99.10279.310303.410498.710201.8:28.9.99.10300.510275.51038610055.2:29.9.99.10274.310213.510408.510119.8:30.9.99.10214.11033710456.310155.8:1.10.99.10335.7102.7310425.910108:4.10.99.10274.610401.210538.310220.4:5.10.99.10401.210400.610578.210250.2:6.10.99.10399.810588.310655.510340.8:7.10.99.10588.31053710687.110431:8.10.99.10534.510649.810743.510423.7:11.10.99.10649.810648.210781.210545.6:12.10.99.10648.810417.110659.610366.1:13.10.99.10412.310232.210495.910173.6:14.10.99.10230.910286.610416.710071.6:15.10.99.10286.610019.710286.69911.43:18.10.99.10018.510116.310221.19884.2:19.10.99.10117.510204.91041810093.8:20.10.99.10203.310392.410485.110144.5:21.10.99.10390.710297.710414.510047.6:22.10.99.10581.710470.210581.710301.2:25.10.99.1046910349.910518.410225.8:26.10.99.10350.910302.110486.410208.7:27.10.99.10302.810394.910515.210172.3:28.10.99.10397.710622.510726.710397.7:29.10.99.10629.210729.910883.110580.1:1.11.99.10730.810648.51082910568.1:2.11.99.10653.710581.810816.110508.1:3.11.99.10582.510609.110759.210485.5:4.11.99.10612.410639.61081810523.4:5.11.99.1064010704.510885.510636.6:8.11.99.10668.410718.810838.710546.7:9.11.99.10715.110617.31080610506.6:10.11.99.10611.910597.71071310449.4:11.11.99.10603.210595.310716.710485.2:12.11.99.10593.510769.310845.210513:15.11.99.10764.710760.810899.210626.8:16.11.99.10762.910932.310992.910691.9
Avatar of nietod
nietod

I suspect at least 1 problem is that you don't have anything seperating your floating point numbers in the output  (start, end, max,min) so then they run together and the procedure to read them gets mixed up.  (It thinks the start of the 2nd number is part of the decimals of the 1st number.  So it reads the 1st number until it comes to the decimal point of the 2nd number.  So eventually it gets screwed up when it reaches the ";" while trying to read a floating point number.

Fix that and see if it helps.
Avatar of DennisWood

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:111088.0:24.8.99.11297.0:511283.0:311404.0:911135.0:8.0......etc...

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.
brain, did you read the question history?
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.
nietod why don't you take the points ? Brain2000 has told the same.
ASKER CERTIFIED SOLUTION
Avatar of nietod
nietod

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
You must be right.  After all, you have over 300,000 points in this area.