gpt4 book ai didi

c++ - 将 wchar 转换为字符串并插入 vector (C/C++)

转载 作者:行者123 更新时间:2023-11-28 03:33:54 26 4
gpt4 key购买 nike

<分区>

我只想将我的 wchar 数组转换为字符串并将其放入我的字符串 vector 中。我的解决方案被注释掉了,因为它不起作用。我得到一个错误,说我的 vector 重载了。代码如下:

  vector<wstring> vec;
string tmp;
int n;
int m_device_id = 0;
do {
m_device_id++;
tmp="";
wprintf(L"\tDevice %d:\r\n", m_device_id);
wprintf(L"\t\tName: %s\r\n", m_device_info.szName);
wprintf(L"\t\tAddress: %02x:%02x:%02x:%02x:%02x:%02x\r\n", m_device_info.Address.rgBytes[0], m_device_info.Address.rgBytes[1], m_device_info.Address.rgBytes[2], m_device_info.Address.rgBytes[3], m_device_info.Address.rgBytes[4], m_device_info.Address.rgBytes[5]);
wprintf(L"\t\tClass: 0x%08x\r\n", m_device_info.ulClassofDevice);

wostringstream tmp;
for (int i = 0; i < 6; i++)
{
tmp << m_device_info.Address.rgBytes [i];

// Append the colon, but not after the last
if (i < 5)
tmp << L':';
}
vec.push_back(tmp.str());

} while(BluetoothFindNextDevice(m_bt_dev, &m_device_info));


vector<wstring>::iterator it = find(vec.begin(), vec.end(), wstring(L"18:22:85:d8:03:98"));
if(it != vec.end()) {
cout << "Found it" << '\n';
} else {
cout << "Not found" << '\n';
}
BluetoothFindDeviceClose(m_bt_
}while(BluetoothFindNextRadio(&m_bt_find_radio, &m_radio));

=============================================

设备信息结构

typedef struct _BLUETOOTH_DEVICE_INFO {
DWORD dwSize;
BLUETOOTH_ADDRESS Address;
ULONG ulClassofDevice;
BOOL fConnected;
BOOL fRemembered;
BOOL fAuthenticated;
SYSTEMTIME stLastSeen;
SYSTEMTIME stLastUsed;
WCHAR szName[BLUETOOTH_MAX_NAME_SIZE];
} BLUETOOTH_DEVICE_INFO;

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com