no operator "<<" matches these operands
Apr 28, 2014 at 8:15pm UTC
Hello, I am trying to write a simple program that demonstrates the use of a structure in an assignment. I keep getting the error no operator "<<" matches these operands on the second "<<" in all three cout statements in the main function. I tried googling it first but in each example of this error I found the author had forgotten "include <string>", however, I cannot see anything I forgot to include. Do you see what is wrong?
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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
#include <iostream>
using namespace std;
struct StatePoll
{
int rep_votes;
int dem_votes;
int ind_votes;
};
void get_vote_data(StatePoll &thing);
void print_bar(int num);
void main()
{
StatePoll thing;
get_vote_data(thing);
cout<<" Republicans: " <<print_bar(thing.rep_votes)<<"\n" ;
cout<<" Democrats: " <<print_bar(thing.dem_votes)<<"\n" ;
cout<<"Independents: " <<print_bar(thing.ind_votes)<<"\n" ;
system("pause" );
}
void get_vote_data(StatePoll &thing)
{
cout<<"Number of votes for republicans: " ;
cin>>thing.rep_votes;
cout<<"\n\n" ;
cout<<"Number of votes for democrats: " ;
cin>>thing.dem_votes;
cout<<"\n\n" ;
cout<<"Number of votes for indepentents: " ;
cin>>thing.ind_votes;
cout<<"\n\n" ;
}
void print_bar(int num)
{
int dots = num/1000;
if (num % 1000 != 0)
{
dots += dots;
}
for (int x=0; x<dots; x++)
{
cout<<"*" ;
}
cout<<"\n" ;
}
Last edited on Apr 28, 2014 at 8:33pm UTC
Apr 28, 2014 at 8:27pm UTC
You're passing the return value of the print_bar function into the stream operator. However, print_bar is a void function and doesn't return anything.
Apr 28, 2014 at 8:32pm UTC
Oh I see, so I need to use the print_bar function outside of my cout statements. Thanks!
Topic archived. No new replies allowed.