Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/130.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/8/file/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
无法打开文件在循环C++中 我有一个C++应用程序,它有以下代码: for (int i = 0; i < ALL_EPID_CERTS_LENGTH; i++) { std::ifstream file(; file.open(path.append(ALL_EPID_CERTS_1_0[i]), std::ios::in | std::ios::binary); if(file.is_open()) { // get the length of the file file.seekg(0, ios::end); size_t fileSize = file.tellg(); file.seekg(0, ios::beg); // create a vector to hold all the bytes in the file vector<byte> data(fileSize, 0); // read the file file.read(reinterpret_cast<char*>(&data[0]), fileSize); byte *tempCerts = new byte[data.size()+1]; memset(tempCerts,0,fileSize+1); std::copy(data.begin(), data.begin()+(data.size()), tempCerts); // !!!!check if NULL and place for NULL are needed for (int j = 0; j < data.size(); j++) { list.push_back(tempCerts[j]); } file.close(); } }_C++_File_Loops - Fatal编程技术网

无法打开文件在循环C++中 我有一个C++应用程序,它有以下代码: for (int i = 0; i < ALL_EPID_CERTS_LENGTH; i++) { std::ifstream file(; file.open(path.append(ALL_EPID_CERTS_1_0[i]), std::ios::in | std::ios::binary); if(file.is_open()) { // get the length of the file file.seekg(0, ios::end); size_t fileSize = file.tellg(); file.seekg(0, ios::beg); // create a vector to hold all the bytes in the file vector<byte> data(fileSize, 0); // read the file file.read(reinterpret_cast<char*>(&data[0]), fileSize); byte *tempCerts = new byte[data.size()+1]; memset(tempCerts,0,fileSize+1); std::copy(data.begin(), data.begin()+(data.size()), tempCerts); // !!!!check if NULL and place for NULL are needed for (int j = 0; j < data.size(); j++) { list.push_back(tempCerts[j]); } file.close(); } }

无法打开文件在循环C++中 我有一个C++应用程序,它有以下代码: for (int i = 0; i < ALL_EPID_CERTS_LENGTH; i++) { std::ifstream file(; file.open(path.append(ALL_EPID_CERTS_1_0[i]), std::ios::in | std::ios::binary); if(file.is_open()) { // get the length of the file file.seekg(0, ios::end); size_t fileSize = file.tellg(); file.seekg(0, ios::beg); // create a vector to hold all the bytes in the file vector<byte> data(fileSize, 0); // read the file file.read(reinterpret_cast<char*>(&data[0]), fileSize); byte *tempCerts = new byte[data.size()+1]; memset(tempCerts,0,fileSize+1); std::copy(data.begin(), data.begin()+(data.size()), tempCerts); // !!!!check if NULL and place for NULL are needed for (int j = 0; j < data.size(); j++) { list.push_back(tempCerts[j]); } file.close(); } },c++,file,loops,C++,File,Loops,在第一次迭代中,循环执行预期的操作,但由于第二次迭代,file.is_open返回false。 所有文件都存在。 你能给我解释一下怎么了吗?你做的是path.append-path是什么?在第一次迭代后,您希望它是什么-可以将所有EPID证书添加到所有EPID证书上吗?您可能需要调用infle.clear;在关闭流后清除状态位,否则无法打开具有相同流的新文件 另外:您确定需要在每次迭代时附加到路径吗?每次追加调用后输出path变量,并检查路径是否正确。我希望在第二次迭代时,路径字符串将如下所示:

在第一次迭代中,循环执行预期的操作,但由于第二次迭代,file.is_open返回false。 所有文件都存在。 你能给我解释一下怎么了吗?

你做的是path.append-path是什么?在第一次迭代后,您希望它是什么-可以将所有EPID证书添加到所有EPID证书上吗?

您可能需要调用infle.clear;在关闭流后清除状态位,否则无法打开具有相同流的新文件

另外:您确定需要在每次迭代时附加到路径吗?每次追加调用后输出path变量,并检查路径是否正确。我希望在第二次迭代时,路径字符串将如下所示:c:/some/path/file1.txtfile2.txt


在这种情况下,我将使用stringstream或sprintf生成路径,并确保不更改路径变量。

您的代码无法编译:std::ifstream file;是无效的C++不同步你的问题,但是你为什么需要引诱符?list.push_backdata[j];也可以。猜测:路径需要重建,而不是不断追加。如果它是std::string,那么在第二次迭代中,它将包含所有EPID\u CERTS\u 1\u 0[0]和所有EPID\u CERTS\u 1\u 0[1]的串联,我不认为这是预期的。@john它追加了in place Yes我的错误,注释已删除。换句话说,path+ALL_EPID_CERTS_1_0[i]不是path。appendALL_EPID_CERTS_1_0[i]是的,这可能是问题所在