6 Replies - 1335 Views - Last Post: 05 May 2010 - 04:04 AM Rate Topic: -----

#1 Guest_Leon*


Reputation:

student_test_array.cpp(43) : error C2679

Posted 05 May 2010 - 12:47 AM

Using vs2008. Compiler error. I've tried changing the names of pretty much all of the variables as well as changing what variables it reads into.

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

const int Student_Number = 5; 

int main()
{
	ifstream in_stream;

	in_stream.open("HW_CH10_P1_Data.txt");
	if (in_stream.fail())
	{
		cout << "There was an error in reading the necessary file.\n";
		exit(1);
	}

	int i;
	int Students_Number[Student_Number];
	int Student_Numbers;
	int Quiz_1[Student_Number], Quiz_2[Student_Number], Test_1[Student_Number], Test_2[Student_Number], Quiz1, Quiz2;
	int target_student, Test1, Test2;
	for(i=0; i<Student_Number; i++)
	{
		in_stream >> Students_Number >> Quiz_1 >> Quiz_2 >> Test_1 >> Test_2;

		Students_Number[i] = Student_Numbers;
		Quiz_1[i] = Quiz1;
		Quiz_2[i] = Quiz2;
		Test_1[i] = Test1;
		Test_2[i] = Test2;
	}
	in_stream.close();



------------------------------------------------------------------------------------------------------------------------
1>c:\users\azaleon\desktop\misc files\chaptersevenproject\chaptersevenproject\student_test_array.cpp(43) : error C2679: binary '>>' : no operator found which takes a right-hand operand of type 'int [5]' (or there is no acceptable conversion)
1>        c:\program files (x86)\microsoft visual studio 9.0\vc\include\istream(1144): could be 'std::basic_istream<_Elem,_Traits> &std::operator >><std::char_traits<char>>(std::basic_istream<_Elem,_Traits> &,signed char *)'
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        c:\program files (x86)\microsoft visual studio 9.0\vc\include\istream(1146): or       'std::basic_istream<_Elem,_Traits> &std::operator >><std::char_traits<char>>(std::basic_istream<_Elem,_Traits> &,signed char &)'
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        c:\program files (x86)\microsoft visual studio 9.0\vc\include\istream(1148): or       'std::basic_istream<_Elem,_Traits> &std::operator >><std::char_traits<char>>(std::basic_istream<_Elem,_Traits> &,unsigned char *)'
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        c:\program files (x86)\microsoft visual studio 9.0\vc\include\istream(1150): or       'std::basic_istream<_Elem,_Traits> &std::operator >><std::char_traits<char>>(std::basic_istream<_Elem,_Traits> &,unsigned char &)'
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        c:\program files (x86)\microsoft visual studio 9.0\vc\include\istream(155): or       'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(std::basic_istream<_Elem,_Traits> &(__cdecl *)(std::basic_istream<_Elem,_Traits> &))'
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        c:\program files (x86)\microsoft visual studio 9.0\vc\include\istream(161): or       'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(std::basic_ios<_Elem,_Traits> &(__cdecl *)(std::basic_ios<_Elem,_Traits> &))'
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        c:\program files (x86)\microsoft visual studio 9.0\vc\include\istream(168): or       'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(std::ios_base &(__cdecl *)(std::ios_base &))'
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        c:\program files (x86)\microsoft visual studio 9.0\vc\include\istream(175): or       'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(std::_Bool &)'
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        c:\program files (x86)\microsoft visual studio 9.0\vc\include\istream(194): or       'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(short &)'
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        c:\program files (x86)\microsoft visual studio 9.0\vc\include\istream(228): or       'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(unsigned short &)'
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        c:\program files (x86)\microsoft visual studio 9.0\vc\include\istream(247): or       'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(int &)'
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        c:\program files (x86)\microsoft visual studio 9.0\vc\include\istream(273): or       'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(unsigned int &)'
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        c:\program files (x86)\microsoft visual studio 9.0\vc\include\istream(291): or       'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(long &)'
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        c:\program files (x86)\microsoft visual studio 9.0\vc\include\istream(309): or       'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(__w64 unsigned long &)'
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        c:\program files (x86)\microsoft visual studio 9.0\vc\include\istream(329): or       'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(__int64 &)'
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        c:\program files (x86)\microsoft visual studio 9.0\vc\include\istream(348): or       'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(unsigned __int64 &)'
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        c:\program files (x86)\microsoft visual studio 9.0\vc\include\istream(367): or       'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(float &)'
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        c:\program files (x86)\microsoft visual studio 9.0\vc\include\istream(386): or       'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(double &)'
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        c:\program files (x86)\microsoft visual studio 9.0\vc\include\istream(404): or       'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(long double &)'
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        c:\program files (x86)\microsoft visual studio 9.0\vc\include\istream(422): or       'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(void *&)'
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        c:\program files (x86)\microsoft visual studio 9.0\vc\include\istream(441): or       'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(std::basic_streambuf<_Elem,_Traits> *)'
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        while trying to match the argument list '(std::ifstream, int [5])'
1>Build log was saved at "file://c:\Users\Azaleon\Desktop\Misc Files\ChapterSevenProject\ChapterSevenProject\Debug\BuildLog.htm"
1>ChapterSevenProject - 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


This post has been edited by baavgai: 05 May 2010 - 03:49 AM
Reason for edit:: tags


Is This A Good Question/Topic? 0

Replies To: student_test_array.cpp(43) : error C2679

#2 Guest_Leon*


Reputation:

Re: student_test_array.cpp(43) : error C2679

Posted 05 May 2010 - 12:53 AM

I do have the closing }. I just didn't want to copy in the code I had commented out and thus I didn't copy it in as well.
Was This Post Helpful? 0

#3 citus  Icon User is offline

  • D.I.C Head

Reputation: 16
  • View blog
  • Posts: 140
  • Joined: 28-March 10

Re: student_test_array.cpp(43) : error C2679

Posted 05 May 2010 - 02:29 AM

in_stream >> Students_Number >> Quiz_1 >> Quiz_2 >> Test_1 >> Test_2;

Students_Number[i] = Student_Numbers;



Did you mean to put "Student_Numbers" after your first ">>" operand instead of what you currently have, which is "Students_Number" which happens to be an array of type int?
Was This Post Helpful? 0
  • +
  • -

#4 Guest_Leon*


Reputation:

Re: student_test_array.cpp(43) : error C2679

Posted 05 May 2010 - 02:39 AM

View Postcitus, on 05 May 2010 - 01:29 AM, said:

in_stream >> Students_Number >> Quiz_1 >> Quiz_2 >> Test_1 >> Test_2;

Students_Number[i] = Student_Numbers;



Did you mean to put "Student_Numbers" after your first ">>" operand instead of what you currently have, which is "Students_Number" which happens to be an array of type int?


wow. Thanks. I forgot I was trying to reference the array type variables I had established. Appreciate it. Got me back on track :)
Was This Post Helpful? 0

#5 citus  Icon User is offline

  • D.I.C Head

Reputation: 16
  • View blog
  • Posts: 140
  • Joined: 28-March 10

Re: student_test_array.cpp(43) : error C2679

Posted 05 May 2010 - 02:59 AM

No problem, glad I could help. I offer this advice to you as well, you can heed or disregard it. Creating variables with extremely similar names almost never turns out well, especially as your program grows. You might want to think about renaming a few of those variables if this program is going to get much bigger. Good luck to you.
Was This Post Helpful? 0
  • +
  • -

#6 Guest_Leon*


Reputation:

Re: student_test_array.cpp(43) : error C2679

Posted 05 May 2010 - 04:01 AM

View Postcitus, on 05 May 2010 - 01:59 AM, said:

No problem, glad I could help. I offer this advice to you as well, you can heed or disregard it. Creating variables with extremely similar names almost never turns out well, especially as your program grows. You might want to think about renaming a few of those variables if this program is going to get much bigger. Good luck to you.


It really didn't get too much bigger. Finished it and it works the way it was supposed to work. I will take your advice in the future though.
Was This Post Helpful? 0

#7 baavgai  Icon User is offline

  • Dreaming Coder
  • member icon

Reputation: 5929
  • View blog
  • Posts: 12,851
  • Joined: 16-October 07

Re: student_test_array.cpp(43) : error C2679

Posted 05 May 2010 - 04:04 AM

Also, use functions and methods. And, for the love of god, parallel arrays are evil; use a struct or a class.

e.g.
#include <iostream>
#include <fstream>
#include <string>

using namespace std;

struct Student {
	int number;
	int quiz_1, quiz_2, test_1, test_2;
};

void loadStudent(istream &in_stream, Student &student) {
	in_stream >> student.number >> student.quiz_1 >> student.quiz_2 >> student.test_1 >> student.test_2;
}

void loadStudents(istream &in_stream, Student list[], int size) {
	for(int i=0; i<size; i++) {
		loadStudent(in_stream, list[i]);
	}
}

bool loadStudentsFromFile(const char *filename, Student list[], int size) {
	ifstream in_stream;

	in_stream.open(filename);
	if (!in_stream.fail()) {
		loadStudents(in_stream, list, size);
		in_stream.close();
		return true;
	}
	return false;
}




int main() {
	const int StudentsSize = 5; 
	Student students[StudentsSize];

	if (!loadStudentsFromFile("HW_CH10_P1_Data.txt", students, StudentsSize)) {
		cout << "There was an error in reading the necessary file.\n";
		return 1;
	}
	
	cout << "Data Loaded" << endl;
	
		
	return 0
}



Note, the naming convention of lower case for variables. If you can distinguish between a variable and some other object, then your code will be easier to debug later.

Hope this helps.

This post has been edited by baavgai: 05 May 2010 - 04:05 AM
Reason for edit:: me also fail code tags

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1