I am trying to import data from a file in my project but I am having trouble finding EOF. Firstly, I used the EOF function as a condition but I after reading this, I tried changed the code but still it is giving same error. Please help me out. Thanks
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
class Rooms;
class Guest;
class MeetingRoomGuest;
Rooms* r_ptr[999];
int r_count=0;
ofstream infile("new.txt",ofstream::binary);
while(infile.read((char *)(&r_ptr[r_count]),sizeof(Rooms)))
{
r_count++;
}
infile.close();
int main ()
{
// some code here
return 0;
}
ERROR:
error C2059: syntax error : 'while'
UPDATE: Please let me know if this is a better implementation?Thanks
int main()
{
r_ptr[r_count]= new Rooms;
while(infile.read((&r_ptr[r_count]),sizeof(Rooms)))
{
r_ptr[++r_count]= new Rooms;
r_count++;
}
infile.close();
//some code here
}
I am still getting an error,
ERROR:
error C2039: 'read' : is not a member of 'std::basic_ofstream<_Elem,_Traits>'
UPDATE: Thanks alot. The code has finally fixed,here is the final implementation,
int main()
{
r_ptr[r_count]= new Rooms;
while(infile.read((char *)(&r_ptr[r_count]),sizeof(Rooms)))
{
r_count++;
r_ptr[r_count]= new Rooms;
}
infile.close();
// some work
}