void File::operator- () { char c; // f2 will be this fp.open(fn,ios::in); int temp = fp.rdstate(); cout <<endl<< "after opening in read mode ; " <<temp; if(temp != 0) { fp.clear(); } fp.close(); fp.open (fn, ios::in | ios::out); int t = fp.rdstate (); cout << "\n In oprt - t=" << t; if (t == 0) { fp.seekg (0, ios::beg); while (1) { fp.get (c); cout <<endl<< "c = " << c; if (fp.eof ()) break; if (!fp.eof ()) { if (c >= 'A' && c <= 'Z') { /* AbCFdEGGD */ c += 32; fp.seekg (-1, ios::cur); fp.put (c); int temp = fp.rdstate(); cout << endl<<"after putting '" << c << "' into file : "<<temp; getchar(); } else if (c >= 'a' && c <= 'z') { c -= 32; fp.seekg (-1, ios::cur); fp.put (c); int temp = fp.rdstate(); cout << endl<<"after putting '" << c << "' into file : "<<temp; getchar(); } } } fp.close (); } }
void student::pack() { int cnt,pos; string temp; string buf = usn + "|" + name + "|" + sem + "|"; if(buf.length() > 45) { error(2); return; } while(buf.length()<46) buf += '_'; pos = hash(usn); fp.open("record11.txt",ios::in); if(!fp) error(1); fp.seekg(pos,ios::beg); getline(fp,temp); fp.close(); cnt = temp[0]-48; if(cnt == 3) { error(3); return; } fp.open("record11.txt",ios::out|ios::in); if(!fp) error(1); if(cnt<0) { fp.seekp(pos,ios::beg); fp.put('1'); pos=pos+1; } else if(cnt==1) { fp.seekp(pos,ios::beg); fp.put('2'); pos=pos+48; } else if(cnt==2) { fp.seekp(pos,ios::beg); fp.put('3'); pos=pos+95; } cout<<"inserting at :"<<pos; fp.seekp(pos,ios::beg); fp<<buf<<endl; fp.close(); }
/** Put an unsigned integer to a stream. @param stream the stream @param value the value to put @param bytes the number of bytes for the value */ void put_unsigned_int(fstream& stream, int value, int bytes) { int temp = value; for (int i = 1; i <= bytes; i++) { stream.put(temp % 256); temp = temp / 256; } }
void myfile::append () { char data; fp.seekg (0, ios::end); cout << "\n\t\tEnter the characters : ['~' is delimiter]"; while ((data = getchar ()) != '~') fp.put(data); }
void myfile::append () { char data; fp.seekg (0, ios::end); cout << "\n\t\tEnter the characters \n\n\t\t '~' is termination character: "; while ((data = getchar ()) != '~') fp.put(data);//writes data to the file }
void File::excise(char line[]) { getName(line); int address = hash(line), counter = 0; bool done = false, removed = false; char name2[recordLen+1]; outfile.clear(); outfile.seekg(address,ios::beg); while (!done && outfile.get(name2,recordLen+1)) { if (!strcmp(line,name2)) { outfile.clear(); outfile.seekg(address+counter*recordLen,ios::beg); outfile.put(delMarker); done = removed = true; } else counter++; if (counter == bucketSize) done = true; else outfile.seekg(address+counter*recordLen,ios::beg); } if (!removed) { done = false; counter = 0; overflow.clear(); overflow.seekg(0,ios::beg); while (!done && overflow.get(name2,recordLen+1)) { if (!strcmp(line,name2)) { overflow.clear(); overflow.seekg(counter*recordLen,ios::beg); overflow.put(delMarker); done = removed = true; } else counter++; overflow.seekg(counter*recordLen,ios::beg); } } if (!removed) cout << line << " is not in database\n"; }
void FM_database::put_int( fstream& fio , index_t i ) { string s = iexts( i ); for (size_t i=0; i<sizeof(index_t); i++) fio.put( s[i] ); }