// File; iss_demo.cpp // Demonstrate using istringstream to parse text #include #include #include #include using namespace std; int main() { ifstream inf("abc.txt"); string line; getline(inf, line); while (!inf.eof()) { // Construct the stringstream with the string istringstream iss(line); // The file format for each line is either: // char dounle int string , if char is 'd' or // char int double , if char is 'i' char c; iss >> c; double d; int i; string s; if (c=='d') { iss >> d >> i >> s; cout << " Got" << c << " " << d << " " << i << " " << s << endl; } else { iss >> i >> d; cout << " Got" << c << " " << i << " " << d << endl; } getline(inf, line); } // while }