- #1
pajak
- 4
- 0
let say i have a simple record file.txt...how can i modified or add data into the record file?
here the sample program
here the sample program
Code:
#include<iostream>
#include<string>
#include <fstream>
using namespace std;
class record
{
private:
string input;
string line;
public :
void insertData(){
ofstream myfile ("example.txt");
if (myfile.is_open())
{
cout <<"Type here : ";
getline(cin,input);
//myfile << "This is a line.\n";
//myfile << "This is another line.\n";
cout <<"Your has type this word : " << input <<endl;
myfile <<"Your has type this word : " << input <<endl;
myfile.close();
}
}
void readData()
{
ifstream myfile ("example.txt");
if (myfile.is_open())
{
while (! myfile.eof() )
{
getline (myfile,line);
cout << line << endl;
}
myfile.close();
}
}
};
int main()
{
record r1;
r1.readData();
r1.insertData();
system ("pause");
return 0;
}