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




int main(){
    const char *months[12]={"January", "February", "March", "April","May", "June", "July", "August","September", "October", "November", "December"}; // to check month is that true or false.
    int day,year;
    string first,last,month;
    Person p(first,last,day,month,year);
    ifstream infile;                   //opening input file
    infile.open("input.txt"); 

    while(!infile.eof()) {

        }
    }
}

I check the values in the Input file and print the correct ones in the output file.I call the setmonth function to check if the month is correct after checking if the day and year are correct in the Input file.

HOW CAN I SOLVE THIS ERROR? AND WHAT IS printInfo FUNCTION PARAMETER?

mmccss
  • 1
  • 1
  • Maybe if you share with us the error log it'd be much more easier... – Skiller Dz May 20 '20 at 19:49
  • `setMonth` doesn't return a value so negating it has no meaning. You might also reconsider `while(!infile.eof())` and instead check to make sure the actual reading is successful. https://stackoverflow.com/questions/5605125/why-is-iostreameof-inside-a-loop-condition-i-e-while-stream-eof-cons – Retired Ninja May 20 '20 at 19:49
  • `if(!p.setMonth(month))` is like `if(!void())` which is like `if(!)` and that doesn't work, because the `!` needs to negate something. – Eljay May 20 '20 at 19:52
  • On a side note, you can write `constexpr char *months[]` to put the array into a compile time context and auto-infer the array size from the right-hand side of the assignment. – Jan Schultke May 23 '20 at 22:20

1 Answers1

1

So the first problem is that you write

if(!p.setMonth(month)) 

which means that setMonth should return a value that can be passed to !. But if you look at setMonth you see this

void setMonth(string m){}

setMonth is a void function, it doesn't return anything so !p.setMonth() is illegal.

Probably it should return a bool

bool setMonth(string m) { ... }

I imagine that void printInfo(ostream){} should be void printInfo(ostream&){}.That's the normal way to pass an output stream to a function.

john
  • 71,156
  • 4
  • 49
  • 68