++ . , . .
, , . ,
12 52
:
52
12 1 132 32554 7 sizeof(int) . . , − . ( ) . .
, , − .
#include <fstream>
using namespace std;
#include "stdlib.h"
#include "math.h"
void error(char *s1,char *s2="") //
{ cerr<<s1<<" "<<s2<<endl; //
exit(1);
}
int main(int argc,char **argv)
{ char *buf=new char[20];
int i;
ifstream f1; //
ofstream f2,f3; //
f1.open(argv[1],ios::in); //
if(!f1) //
error(" ",argv[1]);
f2.open(argv[2],ios::out); // 1
if(!f2) error(" ",argv[2]);
f3.open(argv[3],ios::out); // 2
if(!f3) error(" ",argv[3]);
f1.seekg(0); //
while(f1.getline(buf,20,' ')) // 20
{ if(int n=f1.gcount()) //
buf[n-1]='\0';
//
for(i=0;*(buf+i)&&(*(buf+i)>='0' && *(buf+i)<='9');i++);
if(!*(buf+i)) f2 <<::atoi(buf)<<' '; //
// f2
else f3<<buf<<' '; // f3
}
delete [] buf;
f1.close(); //
f2.close();
f3.close();
}
, (), (). open, close, seekg, getline gcount. .
, ( ) . seekg, tellg , . get put.
|
|
#include <fstream>
using namespace std;
#include "stdlib.h"
void error(char *s1,char *s2="")
{ cerr<<s1<<" "<<s2<<endl;
exit(1);
}
int main()
{ char c,cc;
int n;
fstream f; //
streampos p,pp;
f.open("aaaa",ios::in|ios::out); //
if(!f) error(" ","aaaa");
f.seekp(0); //
while(1)
{ cin>>c; //
if (c=='q' || f.bad()) break;
f.seekg(0,ios::beg); //
while(1)
{ if(((cc=f.get())>=c) || (f.eof()))
{ if(f.eof()) // ,
{ f.clear(0);
p=f.tellg(); // OF
}
else
{ p=f.tellg()-1; //
f.seekg(-1,ios::end); //
pp=f.tellg(); //
while(p<=pp) //
{ cc=f.get();
f.put(cc);
if (--pp>0) f.seekg(pp); //
}
}
f.seekp(p); // p
f.put(c); //
break;
}
}
}
f.close();
return 0;
}
istream get ( ) put ( ). istream ostream - ( ). seekg ( ) seekp ( ).
istream& seekg(streampos pos);
istream& seekg(streamoff off, ios::seek_dir dir);
seekp. os . off ( ) : ios::beg ( ), ios::cur ( ) ios::end ( ). tellg tellp, get put