为什么我会这么恐怖?

Tri*_*Kyu 2 c++ function

可能重复:
错误C2248:'std :: basic_ios <_Elem,_Traits> :: basic_ios':无法访问类'std :: basic_ios <_Elem,_Traits>'中声明的私有成员

error C2248: 'std::basic_ios<_Elem,_Traits>::basic_ios' : cannot access private member declared in class 'std::basic_ios<_Elem,_Traits>'
Run Code Online (Sandbox Code Playgroud)

我应该用这个代码做的是打开两个文件,读取文件,用函数和数组计算文件内部数字的均值和标准差.所以,我收到这个错误,我不确定我的代码有什么问题.我不确定代码有什么问题但它可能是函数吗?我的朋友看了我的代码并得到了这个错误,但之前没有.我应该在某个地方做一个参考,但我把它作为一个值而不是?有人可以帮忙吗?对不起,如果我在发帖时做错了什么.

#include <iostream>
#include <fstream>
#include <cmath>
#include <string> 
#include <iomanip>
using namespace std ;
bool open(ifstream &A_bank, ifstream &B_bank) ;
void read(ifstream &A_bank, ifstream &B_bank, string &n1, string& n2, int &i, int& j,  float &num, float &num1, float &total, float &total1, float counter, float counter1);
void avg(float &mean, float &mean1, float total, float total1, int i, int j);
void print(ifstream A_bank, ifstream B_bank, float mean, float mean1, string n1, string n2);
int main()
 {
    //Declaring variables.
    ifstream A_bank, B_bank ;
    string n1,n2;
    int i, j, a[20], b[20] ;
    float num=0, num1=0, total=0, total1=0, stdev=0,stdev1=0, mean=0, mean1=0, counter, counter1 ;

    open(A_bank, B_bank) ;
    read(A_bank, B_bank, n1, n2, i, j, num, num1, total, total1, counter, counter1) ;
    avg(mean, mean1, total, total1, i, j) ;
    print(A_bank, B_bank, mean, mean1, n1, n2) ;
    return 0;
 }

bool open(ifstream &A_bank, ifstream &B_bank)
{

    string n1, n2;
    cout << "Enter file name: " ;
    getline(cin, n1) ;
    A_bank.open(n1.c_str()) ; 
    if (A_bank.eof())
    {
        cout << "File is empty" << endl ;
        return false ;
    }

    //Verify that the correct file name was entered.
    else if (A_bank.fail())
    {
        cout << "File could not be opened." << endl ;
        return false ;
    }

    cout << "Enter file name of second bank: " ;
    getline(cin, n2) ;
    B_bank.open(n2.c_str()) ;
    if (B_bank.eof())
    {
        cout << "File is empty" << endl ;
        return false ;
    }
    else if (B_bank.fail())
    {
        cout << "File could not be opened." << endl ;
        return false ;
    }
    return true ;
}



//Reading the files
void read(ifstream &A_bank, ifstream &B_bank, string &n1, string& n2, int &i, int& j, float &num, float &num1, float &total, float &total1, float counter, float counter1, int a[], int b[])
{
    getline(A_bank,n1);
    for(int i=0; !A_bank.eof();i++)
    {
        A_bank>>a[i];
        total+=a[i];
        counter++;
    }
    getline(B_bank,n2);
    for(int j=0; !B_bank.eof();j++)
    {
        B_bank>>b[j];
        total+=b[j];
        counter1++;
    }
}

//Calculations
void avg(float &mean, float &mean1, float total, float total1, int i, int j)
{
    mean = (total) / (i) ;
    mean1 = (total1) / (j) ;
}
Run Code Online (Sandbox Code Playgroud)

Ola*_*che 6

print()你试图复制一个ifstream对象时,这是不可能的.ifstream&改为使用:

void print(ifstream &A_bank, ifstream &B_bank, float mean, float mean1, string n1, string n2);
Run Code Online (Sandbox Code Playgroud)

根据std :: basic_ifstream :: basic_ifstream,可以使用C++ 11进行移动.