I believe that ofstream is for writing into a file and ifstream is for reading from a file.
I am trying to write into a file by taking commandline input from the user which is the accept_data() function and and then display all the data from the file that the user entered using display_data() function. I am not sure how to get the input from the commandline from the user.
Here's my code in C++
#include<fstream>
#include<iostream>
#include<cstring>
using namespace std;
class travels {
private:
string customername[20];
int no_of_people;
char package_category;
float cost;
string date[8];
public:
void accept_data();
// void display_data();
};
void travels :: accept_data() {
ofstream ofile;
ofile.open("CUSTFILE.DAT", ios::out | ios::binary);
}
/*void travels :: display_data() {
ifstream Ifile;
Ifile.open("CUSTFILE.DAT");
while(Ifile) {
Ifile.get(customername);
cout<<customername;
}
}*/
int main() {
travels t;
t.accept_data();
//t.display_data();
}