C++ source code ... a program which uses class to read and write to a txt file
koi mistake hai tou thik kar do mujy na khna @Don @ChoCo
Code:
#include <iostream.h>
#include <string.h>
#include <fstream.h>
using namespace std;
class FileHandler
{
private:
fstream file;
string Data;
public:
void SetData(string a)
{
Data=a;
}
void WriteToFile()
{
file.open("file.txt",ios::out);
file<<Data;
file.close();
}
void ReadFromFile()
{
file.open("file.txt",ios::in);
getline(file,Data);
cout<<"The Data was : " <<Data<<endl;
}
};
int main()
{
FileHandler f;
f.SetData("This text should be written on file, if the source code is correct");
f.WriteToFile();
f.ReadFromFile();
system("pause");
}