1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
|
#include <iostream>
#include <algorithm>
#include <vector>
#include <ctime>
#include <cstdlib>
#include <windows.h>
using namespace std;
template<typename type>
void mix(std::vector<std::vector<type>>& vec){
if(vec.empty()) return;
srand(GetTickCount());
int msize = vec.size();
int ssize = vec[0].size();
for(int i ={}; i < msize; ++i) {
int rpos = rand() % msize;
std::vector<type> cpy;
cpy = vec[i];
vec[i] = vec[rpos];
vec[rpos] = cpy;
}
}
template<typename type>
void rem(std::vector<std::vector<type>>& vec, int elemnr){
if(vec.empty() || 0 > elemnr || vec.size() < elemnr) return;
vec.erase(vec.begin() + elemnr);
}
class arr_to_str{
public:
template<typename type>
arr_to_str(std::vector<std::vector<type>>& by) : m_buff{}{
const char * frmt = {};
char temp[10] = {};
//this->m_buff.append("{ ");
for(int i ={}; i < by.size(); ++i){
this->m_buff.append("{ ");
for(int j ={}; j < by[i].size(); ++j){
if(j == by[i].size() - 1) frmt = "0x%02X";
else frmt = "0x%02X, ";
sprintf(temp, frmt, by[i][j]);
this->m_buff.append(temp);
}
this->m_buff.append(" }");
}
//this->m_buff.append(" }");
}
const char * operator()(){
return this->m_buff.c_str();
}
operator const char * (){
return this->m_buff.c_str();
}
private:
std::string m_buff;
};
int main(){
std::vector<std::vector<BYTE>> a = { {0xE3, 0x02, 0x5E, 0x01}, {0x62, 0x02, 0x1F, 0x01}, {0xB7, 0x02, 0x3B, 0x01}, {0xC3, 0x02, 0x42, 0x01}, {0xCA, 0x02, 0x47, 0x01} };
rem(a, 0);
mix(a);
arr_to_str ats(a);
const char * formatted_arr = ats;
cout << formatted_arr[0] << endl;
system("pause");
return 0;
} |
Partager