Supply a vector input with uint8_t array

Windows 11, Visual Studio 2022, C++
I know basic C/C++ but not vectors.
I found code that does base58 encoding. The function is declared as:
 
std::string EncodeBase58(const std::vector<uint8_t>& data, const uint8_t* mapping)

The encoded string is left in the return value, moderately sure of that.
The input below is to be the first argument in the format: hex_to_encode[ i ]
The code will loop through and encode each array into the string.
1
2
3
4
5
6
uint8_t hex_to_encode[ test_array_count ] [ test_array_max_length ] =
{
   { 0x31 },                              
   { 0x41 },
   { 0x61, 0x6c, 0xba, 0xd6, 0x49 },
… };

But now that I get ready to post, I realize the size of the array is not supplied. Is that part of inputting a vector?

I tried this:
1
2
vector<uint8_t> hex_vector[ test_array_count ] [ test_array_max_length ] =
 { { 0x31 }, … };

This seems to me to match the format of several examples I googled up. But it complains about no suitable constructor. I don’t know one either.

How do I present this data to the function so that it will be accepted.
1
2
3
4
std::string EncodeBase58( const std::vector<uint8_t>& data, const std::uint8_t* mapping ) ;

std::string EncodeBase58( const std::uint8_t* data, std::size_t data_sz, const std::uint8_t* mapping )
{ return EncodeBase58( { data, data+data_sz }, mapping ) ; }

You mean a vector of vectors?

1
2
3
4
5
6
vector<vector<uint8_t>> hex_vectors =
{
	{ 0x31 },                              
	{ 0x41 },
	{ 0x61, 0x6c, 0xba, 0xd6, 0x49 },
};

Then you can loop over the vectors using a regular for loop.

1
2
3
4
for (size_t i = 0; i < hex_vectors.size(); ++i)
{
	cout << EncodeBase58(hex_vectors[i], mapping) << "\n";
}

Or you could use a range-based for loop.

1
2
3
4
for (const vector<uint8_t>& hv :  hex_vectors)
{
	cout << EncodeBase58(hv, mapping) << "\n";
}
Last edited on
I did not know that I wanted a vector of vectors, but that does work. I used the option: for( size_t i = 9; ... )

Its a bit more cumbersome than a double indexed array, but it did the job for me.

Thank you for your time.
Last edited on
Registered users can post here. Sign in or register to post.