There are a number of mistakes in your code.
1. If you want to read a file then why use ofstream? You should use ifstream (i is for input, you want something to input to your program). When writing you should use output file stream.
2. You say array of structs and you're using text files. So I can conclude that you want to write string to a file and then read it back and add to your structure. so variable Status is char*
first
second
third
...
it is sufficient to use only char buf[BUFFER_SIZE]
I'll show you this on a simple example and you need to figure out how to use this to solve your problem.
Code:
#include <iostream>
#include <fstream>
using namespace std;
void write_file()
{
ofstream out("data.txt");
out<<"first\n";
out<<"second\n";
out<<"third\n";
out.close();
}
void read_file(char* buffer,int len)
{
ifstream in("data.txt");
while(!in.eof())
{
in.getline(buffer, len);
cout<< buffer<<endl;
// now you can do whatever you like with buffer
}
}
const int BUFFER_SIZE = 1024;
int main()
{
char buffer[BUFFER_SIZE];
write_file();
read_file(buffer,sizeof buffer);
}
If you want to write whole structure to a file then you'll need to use binary files and functions read() and write()
And prototype of getline is:
Code:
istream & getline(char *, int, char = '\n');
So you see now why you're getting a compiler error