/* File: input5.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") ; // open file getline(ifile, firstLine) ; // toss first line while(true) { // keep reading until done ifile >> str1 ; // read 9 fields ifile >> str2 ; ifile >> str3 ; ifile >> str4 ; ifile >> str5 ; ifile >> str6 ; ifile >> str7 ; ifile >> str8 ; ifile >> str9 ; if ( ifile.eof() ) break ; // done? cout << "str1 = '" << str1 << "'\n" ; // print country name /* cout << "str2 = '" << str2 << "'\n" ; // skip printing rest of data 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 }