我要问有关C ++中Ice的问题。我的方法之一要求我传入Ice::ByteSeq。我想从字符串构建此ByteSeq。如何进行转换?

我尝试了以下选项。

Ice::ByteSeq("bytes")        // Invalid conversion to unsigned int
Ice::ByteSeq((byte*)"bytes") // Invalid conversion from byte* to unsigned int
(Ice::ByteSeq)"bytes"        // Invalid conversion from const char& to unsigned int
(Ice::ByteSeq)(unsigned int)atoi("bytes") // Blank (obviously, why did I try this?)


我怎样才能做到这一点?

编辑

"bytes"是占位符值。我的实际字符串是非数字文本信息。

最佳答案

查看headerByteSeqvector<Byte>的别名。您可以按照常规方式从std::string进行初始化

std::string s = "whatever";
Ice::ByteSeq bs(s.begin(), s.end());


或来自具有更多浮点的字符串文字,例如

template <size_t N>
Ice::ByteSeq byteseq_from_literal(char (&s)[N]) {
    return Ice::ByteSeq(s, s+N-1); // assuming you don't want to include the terminator
}

Ice::ByteSeq bs = byteseq_from_literal("whatever");

09-06 22:06