为什么我得到这个错误? [英] Why am I getting this eror?

查看:114
本文介绍了为什么我得到这个错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

错误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>'

我应该用这个代码打开两个文件,读取文件,使用函数和数组计算文件中的数字的平均值和标准偏差。所以,我得到这个错误,我不知道我的代码是什么错。我不是真的确定错误的代码,但它可能是功能?我的朋友看了我的代码,并得到了错误,但它之前没有。我应该在某个地方做一个参考,但我把它作为一个值?有人可以帮助吗?对不起,如果我在处理这则讯息时发生错误。

What I'm supposed to be doing with this code is opening two file, reading the files, calculating the mean and standard deviation from the numbers inside of that file with functions and arrays. So, I am getting this error and I'm not really sure what is wrong with my code. I'm not really sure what is wrong with the code but it could possible be the functions? My friend took a look at my code and got that error but it wasn't there before. Am I supposed to do a reference somewhere but I made it a value instead? Could anyone help? Sorry if I did something wrong while making this post.

#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) ;
}


推荐答案

> print()您正在尝试复制 ifstream 对象,这是不可能的。请改用 ifstream&

In print() you're trying to copy an ifstream object, which is not possible. Use ifstream& instead:

void print(ifstream &A_bank, ifstream &B_bank, float mean, float mean1, string n1, string n2);

根据 std :: basic_ifstream :: basic_ifstream 可以使用C ++ 11移动。

According to std::basic_ifstream::basic_ifstream moving is possible with C++11.

这篇关于为什么我得到这个错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆