Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/133.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++ 在QNX中插入std::basic_ostream实例化的输出时出现内存故障_C++_Qnx - Fatal编程技术网

C++ 在QNX中插入std::basic_ostream实例化的输出时出现内存故障

C++ 在QNX中插入std::basic_ostream实例化的输出时出现内存故障,c++,qnx,C++,Qnx,我有以下情况: #include <iostream> #include <string> #include <sstream> #include <fstream> #include <ostream> class File_ostream final : public std::basic_ostream<char, std::char_traits<char>> { }; int main() {

我有以下情况:

#include <iostream>
#include <string>
#include <sstream>
#include <fstream>
#include <ostream>

class File_ostream final : public std::basic_ostream<char, std::char_traits<char>>
{
};

int main()
{
    const std::string input_file{"file_tests/test.txt.gz"};
    std::ifstream ifs{input_file, std::ios_base::in | std::ios_base::binary};

    File_ostream file_os{};

    file_os << ifs.rdbuf(); // Memory fault (core dumped) 
}
#包括
#包括
#包括
#包括
#包括
类文件\u ostream final:public std::basic\u ostream
{
};
int main()
{
const std::字符串输入_文件{“file_tests/test.txt.gz”};
std::ifstream ifs{input_file,std::ios_base::in | std::ios_base::binary};
文件{ostream文件{};

文件os问题是您使用的是默认构造函数
basic\u ostream
,按照标准,它不存在。我不知道为什么g++和QCC会成功编译您的代码,但它们不应该


无论如何,使用非标准化函数会暴露出非标准化行为,在您的例子中是崩溃。我不知道gcc文档中是否记录了默认构造函数的正确用法,但只要避免使用它,而使用它,就可以解决您的问题。

是故意让构造函数不使用它的参数吗
os
?@sebrockm无论是否使用构造函数,我都有同样的问题。我将更新代码示例。您使用的是哪个编译器?
basic_ostream
没有默认构造函数。任何符合标准的编译器都不会编译提供的代码段。@sebrockm在Linux中使用g++,在QNX中使用QCC。v 5.4.0OK,strange。我验证了gcc确实编译了它,clang也是。msvc无法正确编译它。无论如何,如果它编译,您的
basic_ostream
实例将处于未记录、未标准化的状态。这可能解释了崩溃的原因。请尝试正确的构造函数: