我知道这是一个经常被问到的问题,我没有明确的答案将std :: string或String ^转换为字节数组来写入到一个用于tcp通信的流。将std :: string或string ^转换为C++/cli中的字节数组
这是我曾尝试
bool CTcpCommunication::WriteBytes(const std::string& rdatastr)
{
bool retVal = false;
try
{
if (static_cast<NetworkStream^>(stream) != nullptr)
{
array<Byte>^data = System::Text::Encoding::ASCII->GetBytes(rdatastr);
stream->Write(data, 0, data->Length);
}
}
catch(Exception^)
{
// Ignore, just return false
}
return retVal;
}
我知道这里的GetBytes会不会工作,我还检查编组选项STD转换:字符串.NET字符串,但还没有发现有人any.Can帮助我在解决这个问题..
封送处理到.NET字符串,这是很好描述*无处不在*,与此无关,你正在试图制作一个'数组' –
2012-07-06 04:29:14