gpt4 book ai didi

c++ - 函数中的默认 ofstream 类参数

转载 作者:行者123 更新时间:2023-11-28 03:06:48 25 4
gpt4 key购买 nike

我有功能。如果用户没有在此函数中提供 ofstream 元素:

bool isPolpierwsza(int, bool = false, ofstream = NULL);

比我想签“plik”

bool isPolpierwsza(int liczba, bool wypisz, ofstream plik)

NULL 值。

我的编译器错误:

2.9.cpp:5:48: error: no viable conversion from 'long' to 'ofstream' (aka 'basic_ofstream')
bool isPolpierwsza(int, bool = false, ofstream = NULL);

如何将 ofstream 的默认值设置为像 NULL 或“false”一样对待?

最佳答案

您可以使用两个重载,其中一个采用std::ofstream 参数:

bool isPolpierwsza(int liczba, bool wypisz)
{
return isPolpierwsza(liczba, wypisz, /* your own argument */);
}

关于c++ - 函数中的默认 ofstream 类参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19469462/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com