Feb 23, 2011 at 11:59am UTC
okay in my program atm, it can create a txt file, i now want to be able to read from it and then later on edit it, but all i want to know is how to read from it.
heres parts of the code
what i want to be able to read from the file
1 2 3 4 5 6
char name1 [80];
char phone1 [13];
char address1 [80];
char address2 [80];
char address3 [80];
char postcode [8];
and heres the code im trying to use to read from.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
void menu1op2()
{
ifstream myfile;
myfile.open("wonder.txt" , ios::in);
cout << "Is this correct? \n" ;
getline (myfile,name1[80]);
cout << name1 << "\n" ;
cout << phone1 << "\n" ; // phone number
cout << address1 << "\n" ;
cout << address2 << "\n" ;
cout << address3 << "\n" ;
cout << postcode << "\n" ;
myfile.close();
}
thanks.
Last edited on Feb 23, 2011 at 1:21pm UTC
Feb 23, 2011 at 12:51pm UTC
Easy fix instead of this:
getline(myfile, name1[80]);
use this:
getline(myfile, name1);
see if that works
Feb 23, 2011 at 1:06pm UTC
If you are using character arrays ( ie not std::strings ) you must call the member getline:
myfile.getline ( name1, 80 );
Feb 23, 2011 at 1:18pm UTC
okay thanks will try this now :)
Feb 23, 2011 at 1:21pm UTC
yep works thanks to
myfile.getline ( name1, 80 ); :)