M
mathieu
Hello,
I am looking at the API of std::vector but I cannot find a way to
specify explicitely the size of my std::vector. I would like to avoid
vector::resize since it first initializes the elements of the vector.
Thank you !
Mathieu
Code:
#include <sstream>
#include <vector>
int main()
{
int n = 2048*2048;
std::vector<int> in;
for(int i=0; i<n; ++i)
{
in.push_back( i );
}
std::stringstream ss;
ss.write(reinterpret_cast<char*>(&in[0]), n*sizeof(int));
std::vector<int> out;
//out.resize( n );
out.reserve( n );
ss.read(reinterpret_cast<char*>(&out[0]), n*sizeof(int));
return 0;
}
I am looking at the API of std::vector but I cannot find a way to
specify explicitely the size of my std::vector. I would like to avoid
vector::resize since it first initializes the elements of the vector.
Thank you !
Mathieu
Code:
#include <sstream>
#include <vector>
int main()
{
int n = 2048*2048;
std::vector<int> in;
for(int i=0; i<n; ++i)
{
in.push_back( i );
}
std::stringstream ss;
ss.write(reinterpret_cast<char*>(&in[0]), n*sizeof(int));
std::vector<int> out;
//out.resize( n );
out.reserve( n );
ss.read(reinterpret_cast<char*>(&out[0]), n*sizeof(int));
return 0;
}