Binary and String File Protection

Hello,

I am using private copy constructors to protect my string and binary files.
I am wondering if anybody knows how to write to a binary or string file for input correctly.

Here is the algorithm:

1. Program prompts user to protect the file.
2. If file exists, then a private copy constructor writes over the string or binary without altering it as static.

Here is the source code written in C++:

#include "stdafx.h"
#include <iostream>
#include <string>
#include <fstream>

using namespace std;

class President
{
private:
President() {};
President(const President&);
const President& operator=(const President&);
string Name;

public:
static President& GetInstance()
{
static President OnlyInstance;
return OnlyInstance;
}

string GetFile()
{

cout<<"Enter the name of the file you want to protect: ";
cin>>Name;
ofstream fsOut;
fsOut.open(Name, ios_base::out, ios_base::binary);
if(fsOut.is_open())
{
cout<<"Writing to binary file."<<endl;
fsOut<<Name<<endl;
cout<<"File open successful."<<endl;

fsOut.close();
}
return Name;
}

void SetFile(string InputFile)
{
Name=InputFile;
}

};


int main()
{
string Name;
President& OnlyPresident=President::GetInstance();
OnlyPresident.SetFile(Name);
cout<<President::GetInstance().GetFile()<<endl;
return 0;
}

Topic archived. No new replies allowed.