c++ - 试图从函数返回 std::ifstream

标签 c++

当我尝试使用此函数时,我在两次返回时遇到错误。如果我将它们注释掉,我就不会收到错误。有什么理由为什么这不起作用?

 std::ifstream bipgetConfigurationPath() {
    char bipacfFilename[256], bipacfFullPath[512];
    char *bipconfigPath;
    char *bipdefaultConfigFile;
    const char *bipdefaultConfigFileName;
    bipdefaultConfigFile = "./Resources/plugins/Xsaitekpanels/D2B_config.txt";
    bipdefaultConfigFileName = "D2B_config.txt";
    XPLMGetNthAircraftModel(0, bipacfFilename, bipacfFullPath);
    bipconfigPath = strstr(bipacfFullPath, bipacfFilename);
    strncpy(bipconfigPath, bipdefaultConfigFileName, sizeof(bipacfFilename));
    puts(bipacfFullPath);

    // Check if ACF-specific configuration exists
    std::ifstream bipcustomStream(bipacfFullPath);
    if (bipcustomStream.good()) {
        return bipcustomStream;
    } else {
        std::ifstream bipdefaultStream(bipdefaultConfigFile);
        if (bipdefaultStream.good()) {
            return bipdefaultStream;
        }

    }
}

谢谢比尔

最佳答案

std::streams 不可复制。

关于c++ - 试图从函数返回 std::ifstream,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10180460/

相关文章:

c++ - 用常量值填充 std::vector<double>

c++ - 如何优化动态规划?

c++ - std::shared_ptr 指向的对象何时被删除?

c++ - CoCreateInstance 失败,错误为 "System can not find the file specified"

c++ - 可变参数成员函数模板是否可以有两个参数的基本情况?

c++ - Python 和 C++ 之间的管道不会关闭

c++ - 在 C++ 中返回类型 T

c++ - 多重继承、虚方法冲突和来自基类的指针

c++ - 怀疑std::array C++11库坏了?我该怎么办?

android - Android 上的 QMediaPlayer