程序不会打印出文件中的字符数量

Program wont print out amount of characters that are in a file

你好,我必须制作一个程序来计算给定文本文件中的所有字符 我编译的时候没有错误。但是当我 运行 它提示并获取我的文件的名称但然后结束。这是我的代码。

#include <string>
#include <iostream>
#include"counterType.h"
#include <fstream>
#define MAX 1000
using namespace std;
void countchar(counterType intchar, ifstream& indata);
int main()
{
    ifstream indata;
    counterType intchar;
    cout << "What file would you like to read?" << endl;
    string filename = "empty"; 
    cin >> filename;
    indata.open(filename);
    return 0;
    countchar(intchar, indata);
    intchar.displayCounter();
}

void countchar(counterType intchar, ifstream& indata)
{   
    string x;
    indata >> x;
    while(!indata.eof()) {
        indata >> x;
        intchar.incrementCounter(); 
    }
}   

    return 0;

从函数中生成 return 并阻止执行之后的行。您应该删除它以执行 countchar(intchar, indata);intchar.displayCounter();.