我有一个具有以下代码的 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();
}
}
在第一次迭代中,循环执行预期,但由于第二次 - file.is_open() 返回 false。所有文件都存在。你能解释一下我有什么问题吗???