2.2.3.19.33 vectorbase::SetBytes

Description

Set the elements of this vector from a byte type vector.

Syntax

int SetBytes( vector<byte> & vStream )

Parameters

vStream
[input] vector or internal buffer containing bytes to be copied to this vector

Return

Returns 0 on success or a non-zero error code on failure.

Examples

EX1

//Set byte for int  
void vectorbase_SetBytes_ex1()
{	
	vector<byte> byteArray = {1, 0, 0, 0, 0, 0, 0, 1};
	vector<int> vec(2);  
	// {1, 0, 0, 0} for vec[0], {0, 0, 0, 1}for vec[1]
	vec.SetBytes(byteArray);
	
	for(int ii = 0; ii < vec.GetSize(); ++ii)
	{		
		printf("vec[%d]=%d\n", ii, vec[ii]);
	}
}
	//Result: 
	//vec[0]=1
	//vec[1]=16777216

EX2

//set byte for short
void vectorbase_SetBytes_ex2()
{	
	vector<byte> byteArray = {1, 0, 0, 0, 0, 0, 0, 1};
	vector<short> vS;  
	// {1, 0} for vS[0], {0, 0} for vS[1], {0, 0} for vS[2], {0, 1}for vS[3]
	vS.SetBytes(byteArray);
	
	for(int ii = 0; ii < vS.GetSize(); ++ii)
	{		
		printf("vS[%d]=%d\n", ii, vS[ii]);
	}
}
	//Result: 
	//vS[0]=1
	//vS[1]=0
	//vS[2]=0
	//vS[3]=256

Remark

Set the elements of the vector from an internal buffer.

See Also

vectorbase::GetBytes

Header to Include

origin.h