Error: No operator matches these operands?

Hey guys,
I just started this assignment and I wrote the first bit of code. I'm trying to read data from the keyboard into the timeTwo variable, but I'm getting this operator error for '>>' and I don't know what the problem is. Any help is appreciated.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
  #include <iostream>
#include <string>
#include "ccc_empl.h"
#include "ccc_time.h"

using namespace std;


// main function ***********************************************************

int main ()
{
    Time timeOne;
	Time timeTwo;

	cout << "Please enter the current hour: ";
	cin >> timeTwo.get_hours();
	cout << "Please enter the current minute: ";
	cin >> timeTwo.get_minutes();
	cout << "Please enter the current second: ";
	cin >> timeTwo.get_seconds();

	// End of program statements
	cout << "Please press enter once or twice to continue...";
	cin.ignore().get();    			// hold console window open
	return EXIT_SUCCESS;           	// successful termination 
if i'm guessing correctly, .get_hours() is just an accessor method that returns the hour, and cannot or should not be able to change the value in timeTwo's variables. maybe try storing the cin value in a temporary int, and then passing that into the accessor method that sets the value of the variables?
Thanks much I see what you're saying, but I'm having trouble passing it. It keeps giving me "function as left operand" error.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
int main ()
{
    Time timeOne;
	Time timeTwo();
	int hours;
	int minutes;
	int seconds;
	

	cout << "Please enter the current hour: ";
	cin >> hours;
	cout << "Please enter the current minute: ";
	cin >> minutes;
	cout << "Please enter the current second: ";
	cin >> seconds;

	timeTwo().get_hours = hours;


How would I pass it?
Two things: first, you put parentheses around your object name on line 17, which is why you got the function error. it should be timeTwo.get_hours. Also, could you please post ccc_empl.h and ccc_time.h? it would help me help you.
Last edited on
Topic archived. No new replies allowed.