Hey I am having trouble with the syntax for a program i have to write. I am still learning so go easy on me. I am trying to recover information from a simple text file into a number of arrays using a for loop.
This is the load function im having trouble with.
This is the save function which delimits with /n this worksCode:void load() { int i; char *rcrdpnt; ifstream fin("data.dat"); for (i=0; i<100; i++) { fin.getline( *rcrdpnt) rcrdpnt=(entry[i].name) //fin.getline(entry[i].street); //fin.getline(entry[i].streetii); //fin.getline(entry[i].postcode); } }//end function
I cant seem to work out the syntax I want it to read a whole line from a file into the arrays entry[i].name, entry[i].street, etc. I tried directly using the variable names and using a pointer. Its my understanding you write it in this contextCode:void save(int i) { ofstream fout("data.dat", ios::app); // opens file data.dat for output to the program in append mode. fout << (entry[i].name) << "\n"; // puts name variable of number [i] into a file then starts new line fout << (entry[i].street) << "\n"; fout << (entry[i].streetii) << "\n"; fout << (entry[i].postcode) << "\n"; fout.close(); }// End of Function
fin.getline(variableorpointer, maxamounttoread, delimiting char);
if the delimiting character is not specified it automatically uses /n as the delimiter.
However no matter how much i shift it about it wont compile
I am using VC++ 6 to compile and my lecturer just can't seem to teach. I think its a language barrier thing (He's Iranian i think), also we seem to learning some arcaic form of C++ so Iv'e been trying learn as much as i can on my own.please explain in simple terms I am a noob.
PS I know it should be int main () but my lecturer insists we use void main (void) yes I want to slap him tooy would he be teaching us this?
Any help would be much appreciated![]()



LinkBack URL
About LinkBacks
. I am trying to recover information from a simple text file into a number of arrays using a for loop.


