2013-10-06 2 views
0

저는 초보자 인 C++ 학생이며 jGRASP를 사용 중이며 MinGW32를 설치했습니다. 우리가 과제를 원격으로 Linux 컴퓨터로 돌리므로 작업이 원활하게 이루어질 수 있습니다. Windows 환경에서의 Linux 환경 시뮬레이션 등 MinGW32의 경우 "기본 패키지"를 설치 한 다음 C++ 컴파일러 옵션을 수동으로 선택했습니다. jGRASP에서 나는 settings>>PATH/CLASSPATH>>workspace에 가서 C:\MinGW\mingw32\bin에 새로운 PATH 디렉토리를 추가하여 g ++ 컴파일러의 위치를 ​​알 수 있습니다.MinGW32의 복사 생성자에 대한 Crazy C++ 컴파일러 오류 메시지

jGRASP에서 컴파일 할 때 이러한 미친 오류 메시지가 표시되는데 그다지 이해할 수 없습니다. 나는 iostream 때문에 내 머리글과 관련이 있다고 생각합니다. 여기

ios:42:0, 
       from c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\ostream:38, 
       from c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\iostream:39, 
       from lab1.cpp:6: 
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\ios_base.h: In copy constructor 'std::basic_ios<char>::basic_ios(const std::basic_ios<char>&)': 
ios_base.h:786:5: error: 'std::ios_base::ios_base(const std::ios_base&)' is private 
    ios_base(const ios_base&); 
    ^
ios:44:0, 
       from c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\ostream:38, 
       from c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\iostream:39, 
       from lab1.cpp:6: 
basic_ios.h:66:11: error: within this context 
    class basic_ios : public ios_base 
     ^
In file included from lab1.cpp:8:0: 
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\fstream: In copy constructor 'std::basic_ifstream<char>::basic_ifstream(const std::basic_ifstream<char>&)': 
fstream:427:11: note: synthesized method 'std::basic_ios<char>::basic_ios(const std::basic_ios<char>&)' first required here 
    class basic_ifstream : public basic_istream<_CharT, _Traits> 
     ^
ios:43:0, 
       from c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\ostream:38, 
       from c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\iostream:39, 
       from lab1.cpp:6: 
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\streambuf: In copy constructor 'std::basic_filebuf<char>::basic_filebuf(const std::basic_filebuf<char>&)': 
streambuf:802:7: error: 'std::basic_streambuf<_CharT, _Traits>::basic_streambuf(const std::basic_streambuf<_CharT, _Traits>&) [with _CharT = char; _Traits = std::char_traits<char>]' is private 
     basic_streambuf(const basic_streambuf& __sb) 
    ^
In file included from lab1.cpp:8:0: 
fstream:72:11: error: within this context 
    class basic_filebuf : public basic_streambuf<_CharT, _Traits> 
     ^
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\fstream: In copy constructor 'std::basic_ifstream<char>::basic_ifstream(const std::basic_ifstream<char>&)': 
fstream:427:11: note: synthesized method 'std::basic_filebuf<char>::basic_filebuf(const std::basic_filebuf<char>&)' first required here 
    class basic_ifstream : public basic_istream<_CharT, _Traits> 

그리고 지금까지 내 코드입니다 :

// ---------------------------------------------------------------------------- 
// You write meaningful doxygen comments and assumptions 

#include <string.h> 
#include <iostream> 
#include <iomanip> 
#include <fstream> 
using namespace std; 

int const MAXSIZE = 100;   // maximum number of records in total 
int const MAXLENGTH = 31;   // maximum string length 
int const MAXGRADE = 100;   // highest possible grade 
int const LOWGRADE = 0;    // lowest possible grade 
int const GROUP = 10;    // group amount 
int const HISTOGRAMSIZE = (MAXGRADE-LOWGRADE)/GROUP + 1; // grouped by GROUP 

struct StudentType {    // information of one student 
    int grade;      // the grade of the student 
    char last[MAXLENGTH];   // last name (MAXLENGTH-1 at most) 
    char first[MAXLENGTH];   // first name (MAXLENGTH-1 at most) 
}; 

// prototypes go here 
bool sortInput(ifstream, StudentType, int); 
void displayList(StudentType, int); 
/*setHistrogram(); 
displayHistogram(); 
findAverage();*/ 

//------------------------------- main ---------------------------------------- 
int main() { 
    StudentType students[MAXSIZE]; // list of MAXSIZE number of students 
    int size = 0;     // total number of students 
    int histogram[HISTOGRAMSIZE]; // grades grouped by GROUP 
    int average = 0;     // average exam score, truncated 

    // creates file object and opens the data file 
    ifstream infile("data1.txt"); 
    if (!infile) { 
     cout << "File could not be opened." << endl; 
     return 1; 
    } 

    // read and sort input by last then first name 
    bool successfulRead = sortInput(infile, students, size);    

    // display list, histogram, and class average 
    if (successfulRead) { 
     displayList(students[], size); 
    // setHistogram(... you figure parameters ...); 
    // displayHistogram(... you figure parameters ...); 
    // average = findAverage(... you figure parameters ...); 
     cout << "Average grade: " << average << endl << endl; 
    } 
    return 0; 
} 

bool sortInput(ifstream infile, StudentType students[], int size) 
{ 
    while(infile) 
    { 
     StudentType temp; 
     infile >> temp.last >> temp.first >> temp.grade; 

     //for(int i = MAXSIZE-1; i > MAXSIZE-1-size; i--) 
     for(int i = size; i > 0; i--) 
     { 
     if(strcmp(temp.last, students[i].last) < 0) 
     { 
      //copy current name and grade down 
      //strcopy(students[i+1].last, students[i].last); 
      students[i+1] = students[i]; 
     } 
     else if(strcmp(temp.last, students[i].last) == 0 && strcmp(temp.first, students[i].first) < 0)) 
     { 
      //copy/assign current name and grade down 
      students[i+1] = students[i]; 
     } 
     else 
     { 
      //found right place, break out of loop 
      break; 
     } 
     } 

     //now that you've made room, insert (copy) new name into correct sorted position 
     students[i] = temp; 
    } 

    return true; 
} 

void displayList(StudentType students[], int size) 
{ 
    cout << "List of names sorted:" << end1; 

    for(int i = 0; i < size; i++) 
    { 
     cout << " " << student[i].grade << " " << students[].last << " " << students[i].first << end1; 
    } 
} 

// ---------------------------------------------------------------------------- 
// functions with meaningful doxygen comments and assumptions go here 
+0

코드를 제시해주십시오

bool sortInput(ifstream&, StudentType, int); 

참고 : 그냥에 선언을 변경합니다. 아마 거기에 뭔가 잘못된 것이 있습니다. –

+0

코드가 추가되었습니다. –

+1

확실하지 않음 ... 빈'main' 함수와'include' 및'using' 문을 제외한 모든 코드를 제거 (주석 처리)하십시오. 그런 다음 깨끗한 컴파일을 시도하십시오. (삭제와 실행과'* .obj' 파일을 의미하고, 컴파일을 시도하십시오.) 이것이 도움이되는지보십시오. 그렇다면 한 번에 조금씩 코드를 다시 추가하십시오. 일단 당신이 이해하고, 정확하게 문제를 일으키는 것이 있다면, 여기에 게시하십시오. – osa

답변

1

나는 나 자신이 우연히 여기

#include <string.h> 
#include <iostream> 
#include <iomanip> 
#include <fstream> 
using namespace std; 

컴파일러 에러 메시지입니다. 문제는 sortInput이 참조 대신 값으로 ifstream을 사용한다는 것입니다. ifstream 님이 복사하는 것을 싫어합니다. &

관련 문제