Сбой программы при попытке чтения данных с использованием pclKeyReadData в функции ниже read () При попытке распечатать вектор после функции записи, я могу распечатать данные, помещенные в вектор. Как получить доступ к тем же данным, прочитав pclKeyReadData? поделитесь пожалуйста любыми мыслями
void somefunction(){
write();
}
void write(){
vector<std::pair<string,string>> vec;
cout<<sizeof(vec));
vec.push_back(std::make_pair("x","y"));
vec.push_back(std::make_pair("d","a"));
vec.push_back(std::make_pair("a","b"));
int writeRetVal = 0;
unsigned char* s = (unsigned char*) vec.data();
int x = GetVectorpairSize(vec); //prints 24
writeRetVal = pclKeyWriteData(0xFF, "use", 1, 1, (unsigned char *)s, x);
cout<<writeRetVal
print(vec); //this print function is printing all the data psudhed into vector
read();
}
int GetVectorpairSize(vector<pair<string,string>> vec){
int size = 0;
int char_size = sizeof(char);
for(size_t i = 0; i != vec.size(); i++) {
size = size + char_size*(vec.at(i).first.length()) + char_size*(vec.at(i).second.length());
}
return size;
}
void print(vector<std::pair<string,string>> &vec){
for(size_t i = 0; i != vec.size(); i++) {
LOGI("Bytes Size of userlist is((%s) (%s)",vec.at(i).first.c_str(), vec.at(i).second.c_str());
}
}
void read(){
int size = pclKeyGetSize(0xFF, "use", 1,1);
cout<<size; //prints 24
vector<std::pair<string,string>>vec(3);
//vector<std::pair<string,string>>vec; //this also didn't work
int readRetVal = pclKeyReadData(0xFF, "use", 1, 1, (unsigned char *)vec.data(),size); //crashing in this call
cout<<vec.size()); //prints 3
print(vec); // this prints null all the time
}