/*
Write a program to read string from a file with content given below and store username, date and
time as data members of another class.
175221148 1/1/2018 10:04
175221075 1/1/2018 10:05
*/
#include<iostream>
#include<fstream>
#include<cstdlib>
using namespace std;
ifstream ifs("abc.txt");
class Info
{
long int username;
string date,time;
public:
void accept()
{
string str;
getline(ifs,str,' ');
username=atoi(str.c_str());
getline(ifs,date,' ');
getline(ifs,time,'\n');
}
void display()
{
cout<<"\n\n Username: "<<username;
cout<<"\n Date: "<<date;
cout<<"\n Time: "<<time;
}
};
int main()
{
Info o1,o2;
o1.accept();
o2.accept();
cout<<"\n\n 1 :";
o1.display();
cout<<"\n\n 2 :";
o2.display();
ifs.close();
return 0;
}
Write a program to read string from a file with content given below and store username, date and
time as data members of another class.
175221148 1/1/2018 10:04
175221075 1/1/2018 10:05
*/
#include<iostream>
#include<fstream>
#include<cstdlib>
using namespace std;
ifstream ifs("abc.txt");
class Info
{
long int username;
string date,time;
public:
void accept()
{
string str;
getline(ifs,str,' ');
username=atoi(str.c_str());
getline(ifs,date,' ');
getline(ifs,time,'\n');
}
void display()
{
cout<<"\n\n Username: "<<username;
cout<<"\n Date: "<<date;
cout<<"\n Time: "<<time;
}
};
int main()
{
Info o1,o2;
o1.accept();
o2.accept();
cout<<"\n\n 1 :";
o1.display();
cout<<"\n\n 2 :";
o2.display();
ifs.close();
return 0;
}