5 Replies - 1669 Views - Last Post: 03 October 2009 - 10:15 AM Rate Topic: -----

#1 802989  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 03-October 09

C++ error C2679

Posted 03 October 2009 - 09:48 AM

Hello, I'm taking an introductory C++ programming course and I'm having recurring problems with a certain error. My most recent assignment is to use functions to calculate a number (entered by the user) squared. Here is my code:

#include <iostream>
#include <cmath>
using namespace std;

int square (int num) {
	int result = pow((int)num, 2.0f);

	return result;
}

int main()
{
	cout << "Enter an integer: ";
	int i;
	cin >> i >> endl;
	int k = square(i);
	cout << "The square of " << i << " is " << k;

	return 0;
}



The error that keeps happening is this: "error C2679: binary '>>' : no operator found which takes a right-hand operand of type 'overloaded-function' (or there is no acceptable conversion)". It seems to be pointing to the line with "cin >> i >> endl;". Any help with this would be very much appreciated since this error has occurred in several programs I've tried to write. I am using Microsoft Visual C++ 2005 Express Edition.

*Sorry for posting twice. I did not intend to do that.*

This post has been edited by 802989: 03 October 2009 - 10:04 AM


Is This A Good Question/Topic? 0
  • +

Replies To: C++ error C2679

#2 802989  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 03-October 09

Re: C++ error C2679

Posted 03 October 2009 - 09:50 AM

Hello, I'm taking an introductory C++ programming course and I'm having recurring problems with a certain error. My most recent assignment is to use functions to calculate a number (entered by the user) squared. Here is my code:

#include <iostream>
#include <cmath>
using namespace std;

int square (int num) {
	int result = pow((int)num, 2.0f);

	return result;
}

int main()
{
	cout << "Enter an integer: ";
	int i;
	cin >> i >> endl;
	int k = square(i);
	cout << "The square of " << i << " is " << k;

	return 0;
}



The error that keeps happening is this: "error C2679: binary '>>' : no operator found which takes a right-hand operand of type 'overloaded-function' (or there is no acceptable conversion)". It seems to be pointing to the line with "cin >> i >> endl;". Any help with this would be very much appreciated since this error has occurred in several programs I've tried to write. I am using Microsoft Visual C++ 2005 Express Edition.
Was This Post Helpful? 0
  • +
  • -

#3 zhanfeng  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 75
  • Joined: 09-November 08

Re: C++ error C2679

Posted 03 October 2009 - 09:55 AM

cin >> i >> endl; is wrong. It should be
cin>>i;
cout<<endl;

Was This Post Helpful? 0
  • +
  • -

#4 802989  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 03-October 09

Re: C++ error C2679

Posted 03 October 2009 - 10:02 AM

View Postzhanfeng, on 3 Oct, 2009 - 08:55 AM, said:

cin >> i >> endl; is wrong. It should be
cin>>i;
cout<<endl;


That took care of it! Thank you for your help. And sorry for posting twice, that was not intentional.
Was This Post Helpful? 0
  • +
  • -

#5 zhanfeng  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 75
  • Joined: 09-November 08

Re: C++ error C2679

Posted 03 October 2009 - 10:06 AM

No problemo. :P
Was This Post Helpful? 0
  • +
  • -

#6 Ancient Dragon  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 81
  • View blog
  • Posts: 679
  • Joined: 19-July 09

Re: C++ error C2679

Posted 03 October 2009 - 10:15 AM

>> cin >> i >> endl;

remove the endl -- it can not be used with cin.


>> int result = pow((int)num, 2.0f);

pow() does not return an int. Read this link

This post has been edited by Ancient Dragon: 03 October 2009 - 10:17 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1