error C2275

This is a discussion on error C2275 within the C++ Programming forums, part of the General Programming Boards category; I'm getting this error on line 33: error C2275: 'std::ifstream' : illegal use of this type as an expression I ...

  1. #1
    Registered User
    Join Date
    Apr 2010
    Posts
    3

    error C2275

    I'm getting this error on line 33: error C2275: 'std::ifstream' : illegal use of this type as an expression

    I probably have some other issues too but I think I'm pretty close to finishing. Thanks for any help.

    Here is what I have so far:

    Code:
    #include <iostream>
    #include <iomanip>
    #include <cmath>
    #include <fstream>
    #include <string>
    
    using namespace std;
    
    int openFile(ifstream &rss, string file, string grades);
    void displayHeader();
    void readStuData(ifstream &rss, int scores[], int id[], int &count, bool &tooMany);
    float getAverage(int scores[], int count);
    void assignGrade(int oneScore, float average);
    void reportResults(int id[], int scores[], int count);
    
    const int MAX_SIZE = 10; 
    
    int main()
    {
            ifstream rss;
            string file; 
            string grades;
            int scores[MAX_SIZE];
            int id[MAX_SIZE];
            int i , count = 0, oneScore = 0;
            float avg = 0, average = 0;
            bool tooMany;
    
           
            cout << "Enter filename: ";
            cin >> file;
            
            openFile(ifstream &rss,file,grades);
            displayHeader();
            readStuData(rss,scores,id,count,tooMany);
            getAverage(scores,count);
            assignGrade(oneScore,average);
            reportResults(id,scores,count);
    
            if (tooMany = true)
            {
                    cout << "Average score is: " << getAverage(scores,count) << "%" << endl;
                    cout << "The array is filled. Remaining scores will not be stored.";
                    cout << endl;
            }
            else 
                    reportResults(id,scores,count);
    }
    void reportResults(int id[], int scores[], int count)
    {
            int i;
            int oneScore;
            float average;
            string grades;
    
            for (int i = 0; i < MAX_SIZE; i++)
            {       
                    assignGrade(oneScore,average);
                    cout << id[i] << setw(17) << scores[i] << setw(17) << grades << endl;
            }
    }
    
    void assignGrade(int oneScore, float average)
    {
            string grades, file;
            ifstream rss;
            int scores[MAX_SIZE];
    
            rss >> scores[oneScore];
            oneScore = 0;
            while (!rss.eof() && oneScore < MAX_SIZE)
            { 
                    if (oneScore > average + 10)
                    {
                            grades = "OUTSTANDING"; 
                    }
                    else if (oneScore < average - 10)
                            {
                                    grades = "UNSATISFACTORY";
                            }
                            else
                            {
                                    grades = "SATISFACTORY";
                            }       
                    oneScore++;
                    rss >> scores[oneScore];
            }
    }
    
    float getAverage(int scores[], int count)
    {
            int id[MAX_SIZE];
            int sum = 0;
            float average;
            int i;
    
            for(int i = 0; i < MAX_SIZE; i++)
            {
                    sum += scores[i];
                    count++;
            }
            average = sum / MAX_SIZE;
            return average;
    }
    
    void displayHeader()
    {
            //Output header
            cout << "\nStudent ID" << setw(13) << "Scores" << setw(13) << "Grades"<< endl;
    }
    
    void readStuData(ifstream &rss, int scores[], int id[], int &count, bool &tooMany)
    {
            int tempID;
            int tempScore;
    
            //Get input
            rss >> tempID >> tempScore;
            while(!rss.eof() && (count < MAX_SIZE))
            {
                    id[count] = tempID;
                    scores[count] = tempScore;
                    count++;
                    rss >> tempID >> tempScore;
    
                    if (count > MAX_SIZE)
                    {
                            tooMany = true;
                    }
                    else 
                            tooMany = false;
            }
    }
    
    int openFile(ifstream &rss, string file)
    {
            rss.open(file.c_str());
            if (rss.fail())
            {
          cerr << "ERROR: Cannot open file for input." << endl;
          return EXIT_FAILURE;      
            }
    }

  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,794
    Code:
    cout << "Enter filename: ";
    cin >> file;
            
    openFile(ifstream &rss,file,grades);
    displayHeader();
    readStuData(rss,scores,id,count,tooMany);
    getAverage(scores,count);
    assignGrade(oneScore,average);
    reportResults(id,scores,count);
    Get rid of the red stuff.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  3. #3
    Registered User
    Join Date
    Apr 2010
    Posts
    3
    Ok, I did that and now I get

    fatal error LNK1120: 1 unresolved externals

    &

    error LNK2019: unresolved external symbol

  4. #4
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,794
    Post your new code.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  5. #5
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,648
    Compare
    Code:
    int openFile(ifstream &rss, string file, string grades);
    and
    Code:
    int openFile(ifstream &rss, string file)

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21