All pastes #372748 Raw Edit

Anonymous

public text v1 · immutable
#372748 ·published 2007-02-26 08:07 UTC
rendered paste body
#include <iostream>
using namespace std;
#include <fstream>
#include <string>


//Create Function
int countWords();
int countCharacters();




int countWords( string txtdata )
{
	ifstream file( txtdata.c_str() );
	int count = 0;
	string temp;
	
	
	while (file >> temp) 
	{
		count = count + 1;
	}
	
	return count;
}


int countCharacters( string txtdata )
{
	ifstream file(txtdata.c_str());
	int count = 0;
	char num;
	while (file >> num) 
	{
		count = count + 1;
	}
	
	return count;

}

int main()
{

	cout << "Found " << countWords("txtdata.txt") << " Words" << endl;

	cout << "Found " << countCharacters("txtdata.txt") << " Words" << endl;

	return 0;
}