page 151 #include using namespace std ; int main() { fstream fileobj ; fileobj.open("c:\\exp.txt",ios::out); fileobj << "about time\n" ; fileobj.close() ; return 0 ; } page 153 #include #include using namespace std ; int main() { fstream fileobj ; char nxtStr[20] ; fileobj.open("c:\\exp.txt",ios::in) ; fileobj.getline(nxtStr,20) ; cout<< nxtStr << endl ; cin.get(); return 0 ; } page 153 #include #include using namespace std ; int main() { fstream fileobj ; char nxtStr[20] ; fileobj.open("c:\\exp.txt",ios::out|ios::in); fileobj << "something else\n" ; fileobj.seekg(0) ; fileobj.getline(nxtStr,20) ; cout<< nxtStr << endl ; cin.get(); return 0 ; } page 154 #include using namespace std ; int main() { cout << (ios::out|ios::in )<< endl; cin.get(); return 0 ; } #include using namespace std ; int main() { cout << (3&1)<< endl ; // Binary 11 AND 01 cout << (3&2)<< endl ; // Binary 11 AND 10 cin.get(); return 0 ; } page 155 #include #include using namespace std ; int main() { char rd[4] ; fstream fileobj ; fileobj.open("c:\\exp.txt",ios::out|ios::in); fileobj.write("eds",3) ; fileobj.seekg(0) ; fileobj.read(rd,3) ; cout << rd << endl ; cin.get(); return 0 ; } page 155 #include #include using namespace std ; int main() { fstream fileobj ; fileobj.open("c:\\exp.txt",ios::out|ios::app); fileobj.write("bees",4) ; return 0 ; } page 156 #include #include using namespace std ; int main() { ofstream fileobj ; char nxtStr[20] ; fileobj.open("c:\\exp.txt") ; fileobj << "more text" ; fileobj.close() ; return 0 ; } page 156 #include #include using namespace std ; int main() { char st[10] ; ifstream fileobj ; fileobj.open("c:\\exp.txt") ; fileobj.getline(st,10) ; cout << st << endl ; cin.get(); fileobj.close() ; return 0 ; } page 157 #include #include using namespace std ; int main() { ofstream fileobj("c:\\exp.txt") ; fileobj << "something else" << endl ; return 0 ; } page 157 #include #include using namespace std ; int main() { ifstream fileobj("c:\\exp.txt") ; char nxtStr[20] ; fileobj.getline(nxtStr,20) ; cout << nxtStr << endl ; cin.get(); return 0 ; } page 158 #include #include using namespace std ; int main() { ifstream fileobj ; fileobj.open("c:\\exp ") ; cout << fileobj.rdstate() << endl; fileobj.close() ; return 0 ; } page 158 #include #include using namespace std ; int main() { ifstream fileobj("c:\\expNo.txt") ; cout << fileobj << endl ; cin.get(); fileobj.close() ; return 0 ; } page 158 #include #include using namespace std ; int main() { ifstream fileobj("c:\\expNo") ; if (fileobj == NULL) cout << "error" << endl ; cin.get(); fileobj.close() ; return 0 ; } page 159 #include #include using namespace std ; int main() { ifstream fileobj ; fileobj.open("c:\\expNo.txt") ; cout << fileobj.rdstate() << endl ; cin.get(); fileobj.close() ; return 0 ; } page 159 #include #include using namespace std ; int main() { ifstream fileobj ; fileobj.open("c:\\expNo") ; cout<< (fileobj.rdstate() & ios.failbit) ; cin.get(); return 0 ; } #include using namespace std ; int main() { cout << ios.goodbit << endl ; cout << ios::eofbit << endl ; cout << ios::failbit << endl ; cout << ios::badbit << endl ; cin.get(); return 0 ; } page 160 #include #include using namespace std ; int main() { int x = 2 ; ofstream fileobj ; fileobj.open("c:\\exp.bin",ios::binary) ; fileobj.write(reinterpret_cast(&x),sizeof(int)) ; return 0 ; } page 161 #include #include using namespace std ; int main() { int x = 2, y ; fstream fileobj ; fileobj.open("c:\\exp.bin",ios::out|ios::in |ios::binary) ; fileobj.write(reinterpret_cast(&x),sizeof(int)) ; fileobj.seekg(0) ; cout << fileobj.tellg() << endl ; fileobj.read(reinterpret_cast(&y),sizeof(int)) ; cout << y << endl ; cin.get(); fileobj.close() ; return 0 ; } page 162 #include #include using namespace std ; class part { private: int i ; char s ; public: part() :i(1),s('a') { ;} void display(void) { cout << i << endl ; cout << s << endl ; cin.get(); } } ; ///////////////////////// int main() { part p ; fstream fileobj ; fileobj.open("c:\\exp.bin",ios::out|ios::in |ios::binary) ; fileobj.write(reinterpret_cast(&p),sizeof(part)) ; fileobj.seekg(0) ; fileobj.read(reinterpret_cast(&p),sizeof(part)) ; p.display() ; return 0 ; } page 163 #include using namespace std ; /////////////////////////////// int main() { cout << "hello" << endl ; cin.get(); return 0 ; } /////////////////////////////// page 164 #include using namespace std ; /////////////////////////////// int main(int argc , char* argv[]) { cout << "hello " << argv[1] << endl; cin.get(); return 0 ; } ///////////////////////////////