I'm trying to read a binary file full of std::complex<float>
. I tried the following code, as suggested in this SO answer:
#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;
}
And I get the following compilation error:
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> > (*)())'
I don't understand why can't I access the size method of a vector I just created without compilation errors. I suppose it has something to do with how the vector is being created, but it seems strange to me that it doesn't give an error there instead.
Any explanation for this?