Re: [OBORONA-SPAM] Re: [Dev-C++] Re: RE: need advice on data storage
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Denis K. <di...@ya...> - 2005-03-31 17:22:54
|
Hi. If you want to store some binary information you can store it in
hex or base64 or uue. Then you'll be able to work with it as with usual
ascii strings, store it in files, etc.
Simple example:
class A
{
char* binary_stuff;
int len;
...
public:
friend ostream& operator<<(ostream& os, A& a);
friend istream& operator>>(istream& is, A& a);
...
};
ostream& operator<<(ostream& os, A& a)
{
for(int i=0;i<len;++i)
{
char* c[3]; _itoa(a.binary_stuff[i],c,16);
os<<"0x"<<c<<" ";
}
os<<'\n';
return os;
}
istream& operator>>(istream& is, A& a)
{
string temp; is=getline(temp); int i=0;
while(pos=temp.find(" ")!=-1){
a.binary_stuff[i++]=(temp.substr(0,pos)[3]-31)*16+
(temp.substr(0,pos)[4]-31);
temp=temp.substr(pos+2);
return is;
}
int main()
{
ifstream f1("if.txt");
ofstream f2("of.txt");
A a; f1>>a;
...
f2<<a;
return 0;
}
--
Best regards,
Denis
|