Jump to content
  • Advertisement
Sign in to follow this  
mnowaczewski

HW HELP - URGENT Please!

This topic is 3480 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: /* 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, ' '); inFile.get(grades, '\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() {} The error is on line # 57: inFile.get(grades, '\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
Advertisement
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
Just a note: you need to use [source][/source] tags around your code instead of . [smile]

[Edited by - XTAL256 on March 15, 2009 6:36:42 PM]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!