I have a problem when i am writing a content into a files as a binary format.I noticed, that it writes the content two times into the file.
Here is the code.
#include<iostream>
#include<string>
#include<fstream>
using namespace std;
class store
{
protected:
char pass[50];
public:
fstream file;
store();
~store();
void writing();
void reading();
};
store::store()
{
file.open("binary.dat",ios::in | ios::out | ios::app | ios::binary);
}
store::~store();
{
file.close();
}
int main()
{
store b;
b.writing();
b.reading();
return 0;
}
void store::writing()
{
char buf[] = "hello";
strcpy_s(pass,sizeof(buf),buf);
file.write(reinterpret_cast<char*>(&pass),sizeof(pass));
}
void store::reading()
{
file.seekp(0,ios_base::beg);
while(!file.eof())
{
file.read(reinterpret_cast<char*>(&pass),sizeof(pass));
cout<<pass;
}
}