在 C++ 中: 我有一个 std::set of integers
在 MySQL 中: 我有一个带有 blob 列的表
我想将整数流式传输到 blob 列中,但我不确定该怎么做
编辑: 忘了提到我需要确保整数被打包为小端 DWORD
最佳答案
我不熟悉你正在使用的 MySQL 库,但如果它使用的是 istream,那么它看起来像这样:
void PutInt(istream &stream, int value)
{
uint8_t byte[4];
// converting to little-endian 32bits (DWORD size)
byte[0] = value;
byte[1] = value >> 8;
byte[2] = value >> 16;
byte[3] = value >> 24;
// write to stream
for (int i = 0 ;i < 4; i++)
stream>>byte[i];
}
void PutSet(istream &stream, std::set<int> &some_set)
{
std::set<int>::iterator it;
for (it = some_set.begin(); it != some_set.end(); it ++)
PutInt(stream,(*it));
}
关于c++ - 如何将 std::set 中的值流式传输到 MySQL C++ 连接器 setBlob() 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5424892/