here's some basic code to help you with (what I think is) what you want:
Code:
#include<fstream>
#include<iostream>
int main()
{
char*word=new char[20]; //a character array (C-type string)
int count=0; //to hold the number of words
std::ifstream infile("temp.txt"); //open the file
if(!infile) //if the file doesn't open
{
std::cerr<<"File Input Error"; //output an error
std::cin.get(); //wait for ENTER
delete[]word; //deallocate the character array
exit(1); //exit with a fail status
}
while(infile>>word) //keep going as long as there are more words
count++; //for each word, increase the count by one
infile.close(); //close the file
std::cout<<count<<" words were counted."; //output the count
std::cin.get(); //wait for ENTER
delete[]word; //deallocate the char array
return 0; //return with success status
}
you'll have to modify it to fit your needs though, because I didn't look at how you had your string-based solution fitted into your program.