me again, tad confused with reading from a file?

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
Easy fix instead of this:
getline(myfile, name1[80]);

use this:
getline(myfile, name1);

see if that works
If you are using character arrays ( ie not std::strings ) you must call the member getline:
myfile.getline ( name1, 80 );
okay thanks will try this now :)
yep works thanks to

myfile.getline ( name1, 80 ); :)
Topic archived. No new replies allowed.