Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

problem with fstream

Posted on 1998-09-25
6
Medium Priority
?
218 Views
Last Modified: 2012-05-04
Hi all,

I have had an on going problem with this program I am working on and at this point Iam not sure whether the problem is in my file save function or my file retrieval function.
The problem is that when using getline() (which I need) I can not retrieve the data.

However using the same code except for removing the getline() and using the bit wise operators it works fine until the StationName  has a white space in it. If I remove the stationName all together the rest of the code works perfectly, or if I remove everything except the stationName with getline() it also works perfectly. It almost seems that the combination of the getline() and bitwise operators are the problem.

If the code provided is not adequate let me know and I will be glad to e_mail the code in its entirety.

This is still the same problem from Q.10078727. So the points for both Q's are available.  
I would appreciate any suggestions that might help resolve this problem!

Thanks,
bbarnette
_________________________________________________________________________
void MtrFr::SaveMtrFr(ptrType Data)
// SaveMtrFr() writes all data to HD. Data is a pointer to Head
{

ofstream Fin("mtrconv.txt",ios::binary);

for(ptrType CurrSav = Data; CurrSav != NULL; CurrSav =   CurrSav->Next)
{
Fin<<CurrSav->StationName<<endl;
Fin<<CurrSav->Mon<<" "
<<CurrSav->Day<<" "
<<CurrSav->Yr<<" "
<<CurrSav->Meter_Size<<" "
<<CurrSav->Large_Gear<<" "
<<CurrSav->Small_Gear<<" "
<<CurrSav->Dial_Size<<" "
<<CurrSav->Pulse_Ft<<" "
<<CurrSav->Roc_Conv<<endl;

}
}// end SaveMtrFr()

void MtrFr::Retrieve_Historical_Data()
{
ptrType Tail = NULL;
ptrType CurPtr;
char H_Station_Name[25];
char M_S[5];
unsigned int L_G, S_G ,D_S, Mn, Dy, Yr;
float P_F ,R_C;

Delete_List();

ifstream Fout("mtrconv.txt",ios::binary);

// retrieve data from file
while((Fout.getline(H_Station_Name,25))&& (Fout >> Mn >> Dy >> Yr >> M_S >>  L_G >> S_G >> D_S >> P_F >> R_C))
{
 CurPtr = new TurbMtr;// allocate memory for new node

if(Head != NULL)
{// list already exit, traverse to the next node
Tail->Next = CurPtr;
}
else if(Head == NULL)
{// list does not exit
Head = CurPtr;
Tail = Head;
}

Tail = CurPtr;

strcpy(Tail->StationName, H_Station_Name);
Tail->Mon = Mn;
Tail->Day = Dy;
Tail->Yr = Yr;
strcpy(Tail->Meter_Size, M_S);
Tail->Large_Gear = L_G;
Tail->Small_Gear = S_G;
Tail->Dial_Size = D_S;
Tail->Pulse_Ft = P_F;
Tail->Roc_Conv = R_C;

Tail->Next = NULL;
}  // end while

Fout.close();

}// end Retrieve_Historical_Data()
0
Comment
Question by:bbarnette
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 

Author Comment

by:bbarnette
ID: 1173773
Edited text of question
0
 

Author Comment

by:bbarnette
ID: 1173774
Edited text of question
0
 
LVL 1

Expert Comment

by:newexpert
ID: 1173775
Does it fail on the 1st record or 2nd record?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 22

Expert Comment

by:nietod
ID: 1173776
If you e-mail me the source code and any other files I might need (data files) and/or tell me what data to enter into the program, I will try it.  My address is
nietod@theshop.net
0
 

Author Comment

by:bbarnette
ID: 1173777
It does fail on the second record.
I was also told that I could not use getline() with a binary file. So I changed it to a text file(:: in, ::out) and that did not resolve the problem either.
0
 
LVL 22

Accepted Solution

by:
nietod earned 200 total points
ID: 1173778
Problem solved via e-mail.  The problem was that the input function was not reading the end of the last line of data so subsequent attempts to input were reading from the wrong place in the file.

Look for an e-mail on some suggestions later today.
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

704 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question