У меня есть C++ приложения, которые имеют следующий код:Не удается открыть файл в Loop 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() возвращает ложный. Все файлы существуют. Не могли бы вы объяснить мне, пожалуйста, что не так ???
ваш код не может скомпилировать: 'std :: ifstream file (;' недействителен синтаксис C++ –
Не ваш вопрос, а зачем вам нужны 'tempCerts'?' List.push_back (data [j]); 'будет работать – john
_Guess_: 'путь' нуждается в восстановлении, а не в непрерывном добавлении. – hmjd