Reputation: 944
I am currently implementing a sliding window functionality for a vector<double>
. Problem is I cant seem to cout
the values? When I output it i seem to get memeory location, rather than the actual values..
I need to process the data which the window consist of, so having acess to the values would be neat.
typedef double SAMPLE;
std::vector<std::vector<SAMPLES> > loaded_files;
//Some init
std::vector<SAMPLE>::iterator it;
for (it = loaded_file.samples[0].begin() ; (it + (NUM_SECONDS*SAMPLE_RATE)) != loaded_file.samples[0].end(); ++it)
{
auto window = *it;
std::cout << "printing the window!" << std::endl;
std::cout << &(window) << std::endl; // prints out memory location?
}
Upvotes: 2
Views: 63
Reputation: 1021
Each time you print the window contents, you need to iterate over the window itself. This can be done by changing the contents of your for
loop like so:
typedef double SAMPLE;
std::vector<<SAMPLES>> loaded_files;
//Some init
std::vector<SAMPLE>::iterator it;
for (it = loaded_file.samples[0].begin(); (it + (NUM_SECONDS*SAMPLE_RATE)) != loaded_file.samples[0].end(); ++it)
{
std::cout << "printing the window!" << std::endl;
std::vector<SAMPLE>::iterator wit; // window iterator
for (wit = it; wit != it + (NUM_SECONDS*SAMPLE_RATE); ++wit)
{
std::cout << *wit << ',';
}
std::cout << std::endl;
}
Note that the width of the window is (NUM_SECONDS*SAMPLE_RATE)
. This could be stored in a variable like window_width
or similar to help with readability.
Upvotes: 1
Reputation: 5591
It is not clear what window object is holding. But in your below statement you are providing the address of window. Hence it is printing the address instead of value.
std::cout << &(window) << std::endl; // prints out memory location? YES
Try with below statement:-
std::cout << window << std::endl; // prints out value here
Upvotes: 0