/* File: input4.cpp Testing file I/O using >> with strings. */ #include #include #include #include using namespace std ; int main() { string firstLine ; string str1, str2, str3, str4, str5, str6, str7, str8, str9 ; ifstream ifile("2013WorldBankEducationCensusData.txt") ; getline(ifile, firstLine) ; // toss first line ifile >> str1 ; // read 9 fields ifile >> str2 ; ifile >> str3 ; ifile >> str4 ; ifile >> str5 ; ifile >> str6 ; ifile >> str7 ; ifile >> str8 ; ifile >> str9 ; cout << "str1 = '" << str1 << "'\n" ; // print 9 fields cout << "str2 = '" << str2 << "'\n" ; cout << "str3 = '" << str3 << "'\n" ; cout << "str4 = '" << str4 << "'\n" ; cout << "str5 = '" << str5 << "'\n" ; cout << "str6 = '" << str6 << "'\n" ; cout << "str7 = '" << str7 << "'\n" ; cout << "str8 = '" << str8 << "'\n" ; cout << "str9 = '" << str9 << "'\n" ; ifile.close() ; // put away file when done }