Weird error in this simple code! C2248!

This is a discussion on Weird error in this simple code! C2248! within the C++ Programming forums, part of the General Programming Boards category; Hi Everybody, I am brand new to C++ and am having a bit of trouble accomplishing what should be a ...

  1. #1
    Registered User
    Join Date
    Dec 2005
    Posts
    6

    Weird error in this simple code! C2248!

    Hi Everybody,

    I am brand new to C++ and am having a bit of trouble accomplishing what should be a simple task. What this code is meant to do is count the number of students in a given input text file. I figured putting in a function was a good idea, to reduce the clutter in the main function. This code is actually an excerpt from the whole program, but should serve the right purpose anyway. The error is occurring in both the main code, and this excerpt. I am not sure why it is happening or how to fix it, I would appreciate the help of anyone who is willing.
    Code:
    #include <iostream>
    #include <iomanip>
    #include <fstream>
    #include <string>
    
    using namespace std;
    
    
    
    
    void student_counter(ifstream input2, int& student_count);
    
    int main()
    {
    string studentName;
    int test1,test2,test3,test4,test5;
    char grade = ' ';
    int student_average = 0;
    int student_count = 0;
    double class_average = 0;
    int class_total = 0;
    
    
    ifstream infile;    //input file stream variable
    ofstream outfile;   //output file stream variable
    
    
    infile.open("studentgrades.txt");  //open input file
    outfile.open("results.out");   //open output file
    
    student_counter(infile,student_count);
    
    infile.close();
    outfile.close();
    return 0;
    }
    
    void student_counter(ifstream input2, int& student_count)
    {
    string studentName;
    int test1,test2,test3,test4,test5;
    
    //While there is still data to be read in the input file do the following:
    while (input2)
    {
    input2 >> studentName >> test1 >> test2 >> test3 >> test4 >> test5;
    
    
    if (studentName == "end") 
    {
    	break;
    }
    
    
    student_count++;
    
    }
    
    }

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,558
    It's normally to post the actual text of the error message (which usually includes a line number) along with the code, and especially helpful if you put a comment in the code like
    // "this is line xxx

    Anyway, you need to pass your infile by reference
    void student_counter(ifstream& input2, int& student_count);

  3. #3
    Registered User
    Join Date
    Dec 2005
    Posts
    6

    Thanks a million

    Thank alot, I really appreciate the help!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Simple C code problem
    By neo28 in forum C Programming
    Replies: 24
    Last Post: 05-16-2009, 10:48 AM
  2. Problem with simple piece of code
    By Furious5k in forum C++ Programming
    Replies: 10
    Last Post: 12-12-2008, 04:25 PM
  3. weird things going on in my code
    By -EquinoX- in forum C Programming
    Replies: 6
    Last Post: 11-16-2008, 03:44 AM
  4. Replies: 14
    Last Post: 11-23-2005, 07:53 AM
  5. The following code has one simple error.....
    By bluehead in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 11-08-2001, 06:45 PM

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