Read number of characters from file excluding spaces

Hello, so the question is pretty simple.. How does one read the number of characters in a .txt file excluding the spaces? Here is my code so far. I am getting 67, which is the correct number including spaces but can't find out how to exclude them. Here's my code!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
/////////------------------/////////
      //Function Prototypes//
	int fileLength();


/////////------------------/////////

int main()
{
	ifstream inFile;
	inFile.open("testdata.txt");
	
	string item;
	int count = 0;
	int length = 0;
	
	fileLength();
	
	while(!inFile.eof())
	{
		inFile >> item;
		count++;
		length += item.length();
    } 

}

int fileLength() //Determines and returns the number of characters in the string.
{
	ifstream inFile;
	inFile.open("testdata.txt");
	
	string item;
	int count = 0;
	int length = 0;
		while(!inFile.eof())
	{
		inFile >> item;
		count++;
		length += item.length();
	}
		cout << "Length of characters in this file: " << length << endl;
}


Thanks for any help!
You call your function, but then you ignore its return value and duplicate its code in your main function.

Do not loop on EOF, it is incorrect in your case. Loop on the input operation:
1
2
while(inFile >> item)
{
Topic archived. No new replies allowed.