Is there any way to store an array of integers in one column of table? I want o/p like this:
ident | value
This is one way of serializing and deserializing data:
#include
#include
#include
#include
std::vector deserialize_array(std::string const &csv)
{
std::istringstream parse(csv);
std::vector ret;
for(std::string token; std::getline(parse, token, ','); ret.push_back(token));
return ret;
}
std::string serialize_array(std::string* array_ptr, std::size_t N)
{
std::ostringstream cat;
for(std::size_t index= 0; index< N; ++ index)
cat<< array_ptr[index]<< ',';
std::string ret= cat.str();
return ret.substr(0, ret.size()-1);
}
int main()
{
std::string data= "1,2,3";
std::cout<< "Data: "<< data<< std::endl;
std::vector deserialized= deserialize_array(data);
std::string serialized= serialize_array(deserialized.data(), deserialized.size());
std::cout<< "Serialized + Deserialized: "<< serialized<< std::endl;
}
Instead of spending time parsing parentheses and extra commas, you can serialize as csv and read two by two when processing the deserialized data.