// Ch. 13 Demo Program #2
// written by Mr. Minich
// purpose - to illustrate using getline with AP strings

#include "H:\C++\ClassFiles\apstring.h"
#include <iostream.h> #include <fstream.h>
int main() { apstring nextLine; // a line of the user's input apstring fileName; // file that the user wishes to open ifstream dataFile; // points to sequential access // data file chosen by user int numSpaces = 0; // number of spaces in a line of input // from the data file char nextLetter; // a character from the line of input cout << "Enter a file name with its extension: "; cin >> fileName; dataFile.open(fileName.c_str()); // note the use of the c_str member function getline(dataFile, nextLine); // getting the next line from the file for (int i = 0; i < nextLine.length(); i++) // using the AP string class // member function, length { nextLetter = nextLine[i]; // stripping off the next character // from the inputted line if (nextLetter == ' ') { // counting the blank spaces in a line numSpaces++; // from the file } } cout << "The number of spaces is " << numSpaces << endl; return 0; }// end of main