All pastes #922956 Raw Edit

Untitled

public text v1 · immutable
#922956 ·published 2008-02-29 03:32 UTC
rendered paste body
#include <iostream>
#include <string>
#include <vector>
#include <fstream>
using namespace std;

int main() {

	int count = 0;
	vector<string> file;

	// Create the ifstream object and open a file
	ifstream in("sample_text");	
	string word;
	
	// Add all the words to the file, one at a time
	while (in >> word)
		file.push_back(word);	// need to push the current word onto the vector

	// Iterate through the words, looking for the word "the"
	for (int i = 0; i <= file.size(); i++) {
		cout << file[i] << " ";
		if (file[i] == "the" || file[i] == "The")
			count++;
		}
	cout << "The number of times the word \"the\" was used is: " << count << endl;
	return 0;
}