1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
#include <iostream> #include <string> #include <cctype> #include <fstream> using namespace std; bool at_endl(ifstream&); void skip_blanks(ifstream&); void reformat(string&); void getfilename(string,string&); int main() { string word, filename; char ch; ifstream input; getfilename("input",filename); input.open(filename.c_str()); input >> word; while (!input.eof()) { reformat(word); cout << word; skip_blanks(input); if (at_endl(input)) { cout << endl; } else cout << " "; input >> word; } return 0; } void getfilename(string filetype, string& filename) { cout << "Enter the name of " << filetype << " file\n"; cin >> filename; } bool at_endl(ifstream& input) { return (cin.peek() == '\n'); } void skip_blanks(ifstream& input) { char ch; while (cin.peek() == ' ') cin.get(ch); } void reformat(string& word) { int wlength; wlength = word.length(); word[0] = toupper(word[0]); for (int i=1; i<wlength; i++) word[i] = tolower(word[i]); }
cin
input