8.1, 8.2
This chapter is not a good thing.
IStream &read (IStream &is) { int A; Auto Old_state=is. Rdstate (); is . Clear (); is >>A; is . SetState (old_state); return is ;} int Main () { read (CIN); return 0 ;}
8.3
When you read the EOF or the wrong type
8.4
#include <fstream>using namespacestd;intMain () {Ifstreaminch("Ifile.txt"); Vector<int>VEC; intA; while(inch>>a) vec.push_back (a); for(auto I:vec) cout<<i<<Endl; return 0;}
8.5
#include <fstream>using namespacestd;intMain () {Ifstreaminch("Ifile.txt"); Vector<string>VEC; strings; while(inch>>s) vec.push_back (s); for(auto I:vec) cout<<i<<Endl; return 0;}
8.6, 8.7, 8.8
Temporary:
8.9
#include <sstream>using namespaceStd;istream&read (IStream & is){ strings; Auto Old_state= is. Rdstate (); is. Clear (); while( is>>s) cout<<s<<Endl; is. SetState (old_state); return is;}intMain () {strings; Getline (cin,s); Istringstream is(s); Read ( is); return 0;}
8.10
#include <fstream>#include<sstream>using namespacestd;intMain () {FStreaminch("Ifile.txt"); strings; Vector<string>VEC; while(Getline (inch, s)) {Vec.push_back (s); } for(Auto &C:vec) {Istringstream isout (c); stringWord; while(isout>>word) cout<<word<<Endl; } return 0;}
8.11
Using the clear and STR two member functions
#include <fstream>#include<sstream>using namespacestd;intMain () {FStreaminch("Ifile.txt"); strings; Vector<string>VEC; while(Getline (inch, s)) {Vec.push_back (s); } Istringstream isout; for(intI=0; I<vec.size (); ++i) {isout.clear (); Isout.str (Vec[i]); stringWord; while(isout>>word) cout<<word<<Endl; } return 0;}
8.12
?
8.13
Temporary:
"C++primer" v5 the 8th Chapter IO Library reading notes Exercise answer