Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/132.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如何解决参数为一元的错误?_C++_Class_Exception_Composition - Fatal编程技术网

C++ 如何解决参数为一元的错误?

C++ 如何解决参数为一元的错误?,c++,class,exception,composition,C++,Class,Exception,Composition,我检查输入文件中的值并在输出文件中打印正确的值。在检查输入文件中的日期和年份是否正确后,我调用setmonth函数检查月份是否正确 如何解决此错误? 什么是printInfo函数参数?因此,第一个问题是您要编写 #include<iostream> #include<fstream> #include<string> using namespace std; int main(){ const char *months[12]={"Januar

我检查输入文件中的值并在输出文件中打印正确的值。在检查输入文件中的日期和年份是否正确后,我调用setmonth函数检查月份是否正确

如何解决此错误?
什么是printInfo函数参数?

因此,第一个问题是您要编写

#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()) {

        }
    }
}
这意味着setMonth应该返回一个可以传递给!的值!。但是如果你看看setMonth你会看到这个

if(!p.setMonth(month)) 
setMonth是一个空函数,它不会返回任何值!p、 这个月是非法的

也许它应该返回一个布尔值


我想void printInfoostream{}应该是void printInfoostream&{}。这是将输出流传递给函数的正常方式。

如果您与我们共享错误日志,可能会容易得多……setMonth不会返回值,因此对其进行否定没有任何意义。你也可以重新考虑一下!改为检查以确保实际读数成功。如果p、 setMonthmonth就像是如果!虚空就像是如果!这不起作用,因为!需要否定某些内容。另一方面,您可以编写constexpr char*months[]将数组放入编译时上下文,并从赋值的右侧自动推断数组大小。
void setMonth(string m){}
bool setMonth(string m) { ... }