Need Help To diplay data from txt file correctly

Hi


i'm now workink on phonebook program that insert delete display search update

records

i have no problem with iinserting data into file and each record is in line


but the problem when trying to display data from txt file

it diplayed incorrectly for example i may have have half of a record in a line
and the rest of it in another line

i can't figure out where is the problem

could help me please

this is my code


#include <cstdlib>
#include <iostream>
#include <fstream>

using namespace std;

class phonebook
{

public :
char Phone_Number [20];
char First_Name [20];
char last_Name [20];
char Adress [20];
char City [20];
char Email [20];
};


void insert ()
{
phonebook p ;
ofstream myfile ;
myfile.open("E:\\test.txt",ios::app);
cout << "Enter Phone Number " ;
cin>> p.Phone_Number;
myfile << p.Phone_Number<<'|';
cout<<endl;
cout<<"Enter First Name " ;
myfile <<p.Phone_Number<<'|';
cin>> p.First_Name;
cout<<endl;
cout<<"Enter Last Name " ;
cin>>p.last_Name;
myfile << p.last_Name<<"\n";
cout<<endl;
myfile.close();



}


void Display ()
{

fstream myfile ;
myfile.open("E:\\test.txt",ios::in);

phonebook p ;



while(!myfile.eof())
{

myfile.getline(p.Phone_Number,20,'|');
cout <<p.Phone_Number<<"|";
myfile.getline(p.First_Name,20,'|');
cout<<p.First_Name<<"|";
myfile.getline(p.last_Name,20,'|');
cout<<p.last_Name<<"\n";
cout<<"\n";







};






}




void Search (char key[])
{
ifstream myfile;
myfile.open("E:\\test.txt",ios::in);


}

int main(int argc, char *argv[])
{
insert();
Display();
system("PAUSE");
return EXIT_SUCCESS;
}
Well if you can't figure something out that has to do with files or streams just remember that every character is actually an ascii value.

http://www.asciitable.com/

so simply, where the problem is, output what is actually at that exact point, and compare with what you expect.

1
2
char buf = file.get();
cout << (int)buf; //output the ascii value of the int. 
Topic archived. No new replies allowed.