//-------------------------------------------------------------------- // // Example showing how to pass ioparam.cpp // an I/O stream to a function // //-------------------------------------------------------------------- #include // For cin and cout #include // For file input/output //-------------------------------------------------------------------- // // Function prototypes showing I/O stream function parameters. void getWord ( istream &inStream, char *word ); void outputWord ( ostream &outStream, char *word ); //-------------------------------------------------------------------- void main() { const int maxWordLength = 21; // Max # chars. in word char word[maxWordLength]; // Word ifstream inFile("word.dat"); // Input file ofstream outFile("word.out"); // Output file // Read word from cin and output it to cout. cout << "Enter word: "; getWord(cin,word); outputWord(cout,word); // Read word from inFile and output it to outFile. getWord(inFile,word); outputWord(outFile,word); // Close the files inFile.close(); outFile.close(); } //-------------------------------------------------------------------- void getWord ( istream &inStream, char* word ) // Reads a word from inStream. { inStream >> word; } //-------------------------------------------------------------------- void outputWord ( ostream &outStream, char* word ) // Outputs a word to outStream. { outStream << word << endl; }