Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/asp.net-mvc-3/4.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++ ostream无法打开文件,因为打开的文件太多_C++_Ostream - Fatal编程技术网

C++ ostream无法打开文件,因为打开的文件太多

C++ ostream无法打开文件,因为打开的文件太多,c++,ostream,C++,Ostream,下面是我曾经调用过的函数!正如我所见,它会打开文件一次! 但我不明白为什么它返回太多打开的文件。它和向量的大小有关吗 void WriteResult(std::vector<result*> result) { std::string tempStr = ""; std::string outPath = "/my/path/similarityScores.txt" ; for ( int i=0; i< result.size(); i++)

下面是我曾经调用过的函数!正如我所见,它会打开文件一次! 但我不明白为什么它返回太多打开的文件。它和向量的大小有关吗

void WriteResult(std::vector<result*> result)
{
    std::string tempStr = "";
    std::string outPath = "/my/path/similarityScores.txt" ;
    for ( int i=0; i< result.size(); i++)
        tempStr += (*result[i]).GetResult();
    outStream.open(outPath.c_str(), std::ios::app );
    if (!outStream)
        std::cout << std::strerror(errno) << '\n';  
    outStream << tempStr;
    outStream.close();
}
试一试

顺便说一句,考虑用每个stl方法替换太多打开的文件是计算机的一个问题,每个用户都有一个全局限制,一次可以打开多少文件。您可以使用类似lsof的程序查看当前打开的文件


尝试重新启动计算机并再次运行程序。

打开的文件太多可能是操作系统的限制,但大多数情况下,这是程序的限制;在某个地方,程序正在打开一个文件,但无法关闭它。但是带有lsof的提示仍然有效。可能OP确实打开了太多类似内存泄漏的文件,或者另一个应用程序出错。这很可能会指出罪魁祸首。您很可能打开了文件,但在进入WriteResult之前尚未关闭这些文件。
for ( int i=0; i< result.size(); i++)
**{**tempStr += (*result[i]).GetResult();**}**
outStream.open(outPath.c_str(), std::ios::app );