Я пытаюсь прочитать двоичный файл, полный std::complex<float>
. Я попытался следующий код, as suggested in this SO answer:Не удается получить векторный размер при построении из istreambuf_iterator
#include <complex>
#include <iostream>
#include <iterator>
#include <fstream>
#include <string>
#include <vector>
void readRawFile(const std::string inputFile){
std::ifstream input(inputFile, std::ios::binary);
std::vector<std::complex<float>> auxBuffer(std::istreambuf_iterator<std::complex<float>>(input), std::istreambuf_iterator<std::complex<float>>());
std::cout << "Number of raw samples read: " << auxBuffer.size();
}
int main(){
readRawFile("myRawFile.raw");
return 0;
}
И я получаю следующее сообщение об ошибке компиляции:
In function 'void readRawFile(std::string)': 12:59: error: request for member 'size' in 'auxBuffer', which is of non-class type 'std::vector<std::complex<float> >(std::istreambuf_iterator<std::complex<float> >, std::istreambuf_iterator<std::complex<float> > (*)())'
Я не понимаю, почему я не могу получить доступ к методу размера вектора я только что создал без ошибок компиляции. Я полагаю, что это имеет какое-то отношение к тому, как создается вектор, но мне кажется странным, что вместо этого там не возникает ошибка.
Любые объяснения для этого?
Большинство Vexing Parse? – WhiZTiM