FileOprations

 #include <iostream>

#include <fstream>
#include<cstdio>
#include<stdio.h>
#include <string>
using namespace std;

class FileOp {

public:
void CreateFile() {
string filename;
cout << "Please Inpute File Name:\n";
cin >> filename;

cout << "Please Inpute Data:\n";
/* string data;
getline(cin, data);*/
char data[256];
cin >> data;

ofstream file(filename);
if (file.is_open()) {
file<< data;
file.close();
cout << "File Create Sucess.";
}
}
};

int main() {

FileOp obj;
int code;
cout << "Opration" << endl;
cout << "1 Create New File" << endl;
cout << "2 Read File" << endl;
cout << "3 Append Data" << endl;
cout << "4 Delete File" << endl;

cout << "\n Please Enter Code:\n";
cin >> code;

switch (code)
{
case 1:
obj.CreateFile();
break;
case 2:
break;
case 3:
break;
case 4:
break;

default:
cout << "Invalid code.";
break;
}

return 0;
}

Comments

Popular posts from this blog

Dynamic Memory2

Smart Pointer unique_ptr, shared_ptr, weak_ptr

Run Time Polymorphism ( Function override )