更新时间:2022-04-13 15:37:43
来自https://github.com/aws/aws-sdk-cpp/issues/416。谢谢Bu11etmagnet!
如果您有一个要传递给Aws函数的std::string
,请从它构造一个Aws::String
std::string s{"whatever"};
Aws::String aws_s(s.c_str(), s.size());
Aws::SomeFunction(aws_s);
如果从Aws函数获得Aws::String,请从它构造std::String:
Aws::String const& aws_s = Aws::SomeFunction();
std::string s(aws_s.c_str(), aws_s.size());
遗憾的是,这两个命令都执行字符串内容的副本。
Aws::String aws_s(std_string.c_str())
将使用strlen()测量字符串长度,该信息已包含在std::String对象中。