Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/visual-studio-2010/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
不能编译C++代码,因为IFSULL是不可访问的_C++_Visual Studio 2010_Visual C++_Fstream_Ifstream - Fatal编程技术网

不能编译C++代码,因为IFSULL是不可访问的

不能编译C++代码,因为IFSULL是不可访问的,c++,visual-studio-2010,visual-c++,fstream,ifstream,C++,Visual Studio 2010,Visual C++,Fstream,Ifstream,我不知道为什么它不能被编译 错误1错误C2248: “std::basic_ifstream::basic_ifstream”:无法访问 在类中声明的私有成员 'std::basic\u ifstream'c:\users\hisham\documents\visual studio 2012\projects\homework4\a04.cpp 39 1 homework4错误2错误 C2248:'std::basic_ifstream::basic_ifstream':无法 访问类中声明的私

我不知道为什么它不能被编译

错误1错误C2248: “std::basic_ifstream::basic_ifstream”:无法访问 在类中声明的私有成员 'std::basic\u ifstream'c:\users\hisham\documents\visual studio 2012\projects\homework4\a04.cpp 39 1 homework4错误2错误 C2248:'std::basic_ifstream::basic_ifstream':无法 访问类中声明的私有成员 'std::basic\u ifstream'c:\users\hisham\documents\visual studio 2012\projects\homework4\a04.cpp 40 1 homework4 3 IntelliSense: std::basic_ifstream::basic_ifstreamconst std::basic_ifstream::_Myt&_Right[带_Elem=char, _Traits=std::char_Traits]在C:\Program Files x86\Microsoft Visual Studio 11.0\VC\include\fstream的第827行声明 无法访问的c:\Users\Hisham\Documents\Visual Studio 2012\Projects\Homework4\a04.cpp 39 11 Homework4智能感知: std::basic_ifstream::basic_ifstreamconst std::basic_ifstream::_Myt&_Right[带_Elem=char, _Traits=std::char_Traits]在C:\Program Files x86\Microsoft Visual Studio 11.0\VC\include\fstream的第827行声明 无法访问的c:\Users\Hisham\Documents\Visual Studio 2012\Projects\Homework4\a04.cpp 40 11 Homework4

谢谢。

错误并不是说ifstream不可访问。它以自己复杂的方式表示复制构造函数是不可访问的,因为它被声明为私有的。问题是您正在按值传递ifstream,它试图调用不可访问的复制构造函数

    //**************************************************************************************************************
// FILE: a04.cpp
//**************************************************************************************************************
#include <fstream>
#include <iostream>
#include "Sorter.hpp"
using namespace std;
// Write the function header for Merge ()
void Merge(int a[] , int b[],int c[], int n)
{
    int i = 0, j = 0, k = 0;
    while (i < n || j < n) {
        // Write the if-elseif-elseif-... statement in the body of the while loop
        if (i < n  && j < n && a<=b) {
                c = a;
                i++;
        }
        else if (i < n && j < n && a > b) {
            c =b;
            j++;
        }
        else if (i < n) {
            c = a;
            i++;
        }
        else {
            c =b;
            j++;
        }
        k++;
    } // end while
} // end function merge

void ReadList(ifstream fin, int a[], int n);

void ReadFile(int a[], int b[], int& n)
{
    ifstream fin ("ints-in.txt");
    ReadList(fin,a,n); // come back again different than the psuedo code
    ReadList(fin,b,n);
    fin.close();
} 


// Write the function header for ReadList()
void ReadList(ifstream fin, int a[], int n)
{
    n = 0;
    int number;
    // Implement the sentinel loop
    while (fin >> number && number != -1) {
        a[n] = number;
        n++; // come back again
    }
}


void WriteFile(int a[], int n)
{
    ofstream fout("ints-out.txt");
    // Write a vary loop where variable ivaries from 0 to n - 1. In the loop send a[i] and ' ' to fout.
    for (int i =0; i <= n-1; i++) {
        fout << a << ' '; // come back again.
    }
    fout << -1;
    fout.close();
}


int main()
{
// Define int arrays a,b, and c and int variable n.
int a[100], b[100], c[200];
int n;

// Call ReadFile () passing a,b, and n
ReadFile(a,b,n);

// Define and create a Sorter object named sorter
Sorter sorter;
// Call SelectionSort() on sorter to sort a into ascending order.
// Hint: to access the ASCENDING constant data member of the Sorter class you write Sorter::ASCENDING.
sorter.SelectionSort(a,100,Sorter::ASCENDING); //come back again here.

// Call BubbleSort () on sorter to sort b into ascending order
sorter.BubbleSort(b,100,Sorter::ASCENDING);
// Call Merge() passing a,b,c, and n
Merge(a,b,c,n);
// Call WriteFile () passing c and 2n
WriteFile(c,2*n);

return 0;
} 
而是通过引用传递它

void ReadList(ifstream fin, int a[], int n)

iostream不可复制,因此无法按值传递它们

void ReadList(ifstream & fin, int a[], int n)
您正试图通过副本传递istream实例。您不能这样做-复制构造函数被标记为私有

您需要将ReadList函数声明为:

void ReadFile(int a[], int b[], int& n)
{
    ifstream fin ("ints-in.txt");
    ReadList(fin,a,n); // come back again different than the psuedo code
    ReadList(fin,b,n);
    fin.close();
} 

void ReadList(ifstream fin, int a[], int n)

我一直在编写相同的代码,在Merge函数中有一些不同的东西

void ReadList(ifstream& fin, int a[], int n)
我把I,j,k放在括号里。 我不确定这是否正确,但我还没有收到这方面的任何错误消息

void Merge(int a[], int b[], int c[], int& n)
 {
   int i = 0, j = 0, k = 0;
   while (i < n || j < n) 
 {
    if (i < n && j < n && a[i] <= b[j])
     {c[k] = a[i];
    i++;}
    else if (i < n  && j < n && a[i] > b[j])
     {c[k] = b[j];
     j++;}
    else if (i < n)
    {c[k] = a[i];
    i++;}
     else
     {c[k] = b[j];
    j++;}
    k++;
      }
  }