Sign in to follow this  

HW HELP - URGENT Please!

This topic is 3195 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey... I cannot for the life of me figure out why I keep getting this error. Here is the code: [CODE] /* File Name: Scores.cpp Author: <Matt Nowaczewski> Created on: <03/14/09> Descr: Performs tasks outlined in Lab#5a tasks 1 & 2. */ // Includes #include <iostream> #include <fstream> using namespace std; // Global Variables const int MAX_STUDENTS = 10;// The maximum number of students. const int MAX_CHARS = 20;// The maximum number of characters for student name. // Function Prototypes /* ReadData: Complies with tasks per task 2. */ int ReadData(fstream &inFile, char[MAX_STUDENTS][MAX_CHARS], int[MAX_STUDENTS][1], int maxReads); /* WriteData: Complies with tasks per task 2. */ void WriteData(char studentNames[MAX_STUDENTS][MAX_CHARS], int [MAX_STUDENTS][1], int numOfStudents); int main(void) { // Variable Definitions char studentName[MAX_STUDENTS][MAX_CHARS] = {0,0}; int grades[MAX_STUDENTS][1] = {0,0}; // Grab data and insert into arrays. fstream inFile; ReadData(inFile, studentName, grades, MAX_STUDENTS); }// int main(void) {} // Function Definitions int ReadData(fstream &inFile, char studentNames[MAX_STUDENTS][MAX_CHARS], int grades[MAX_STUDENTS][1], int maxReads) { // Open the file inFile.open("C:\\grades.txt"); if (!inFile) { cout << "Error: The file could not be found."; } // Process file contents int i = 0; do{ inFile.getline(studentNames[i], ' '); inFile.get(grades[i], '\n'); i++; }while(i < maxReads && !inFile.eof()); return i;// Number of reads. }// int ReadData() {} void WriteData(char studentNames[MAX_STUDENTS][MAX_CHARS], int [MAX_STUDENTS][1], int numOfStudents) { }// void WriteData() {} [/CODE] The error is on line # 57: inFile.get(grades[i], '\n'); The exact error message: 1>------ Build started: Project: LAB5A, Configuration: Debug Win32 ------ 1>Compiling... 1>Scores.cpp 1>c:\documents and settings\matt\my documents\visual studio 2005\projects\lab5a\lab5a\scores.cpp(57) : error C2664: 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::get(_Elem *,std::streamsize)' : cannot convert parameter 1 from 'int [1]' to 'char *' 1> with 1> [ 1> _Elem=char, 1> _Traits=std::char_traits<char> 1> ] 1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast Why would it say that? I don't even understand why the heck it would try to convert parameter 1 from int to char *... It's an INT array, so why a char pointer data type...So confused SOS!!!

Share this post


Link to post
Share on other sites
The grades variable is an array of ints, but when you use the square brackets with an index you are accessing a particular element of the array. So you are passing an integer to the function.

If you look at the documentation for the get function, you'll see that it takes a char pointer, not an int pointer.

Share this post


Link to post
Share on other sites

This topic is 3195 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this