//: C04:Istring.cpp // From "Thinking in C++, Volume 2", by Bruce Eckel & Chuck Allison. // (c) 1995-2004 MindView, Inc. All Rights Reserved. // See source code use permissions stated in the file 'License.txt', // distributed with the code package available at www.MindView.net. // Input string streams. #include #include // For fabs() #include #include // For epsilon() #include #include using namespace std; int main() { istringstream s("47 1.414 This is a test"); int i; double f; s >> i >> f; // Whitespace-delimited input assert(i == 47); double relerr = (fabs(f) - 1.414) / 1.414; assert(relerr <= numeric_limits::epsilon()); string buf2; s >> buf2; assert(buf2 == "This"); cout << s.rdbuf(); // " is a test" } ///:~