#include<fstream.h>
#include<iostream.h>
#include<string.h>
using namespace std;
class emp
{
public:
char *per;
int i;
int write2()
{
ofstream out("ss.txt",ios::app | ios::binary );
cout<<"Enter some character ....\n";
per = new char[100];
cin.getline(per,100,'\n')
out.write("\n",1);
out.write(per,strlen(per));
out<< "\n";
per = "asdfgh";
out.write(per,strlen(per));
out.write((char *)&i,5);
out.write(per,strlen(per));
return 0;
}
int read_2()
{
char * buffer;
long size;
ifstream in("ss.txt",ios::in|ios::binary|ios::ate);//try without any of these flags.
size = in.tellg();
in.seekg (0, ios::beg);
buffer = new char [size];
in.read (buffer, size);
in.close();
cout << "the complete file is in a buffer...\n";
cout<<buffer;
delete[] buffer;
return 0;
}
};
void main()
{
emp e;
e.write2();//Writes to a file in binary format even if the input data has space. eg:-
e.read_2();//Reads a binary file.
}
mksakeesh 0 Newbie Poster
William Hemsworth 1,339 Posting Virtuoso
mksakeesh 0 Newbie Poster
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
William Hemsworth 1,339 Posting Virtuoso
mksakeesh 0 Newbie Poster
William Hemsworth 1,339 Posting Virtuoso
mksakeesh 0 Newbie Poster
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
mksakeesh 0 Newbie Poster
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.