我只想将我的 wchar 数组转换为字符串并将其推送到我的字符串向量中。我的解决方案被注释掉了,因为它不起作用。我收到一个错误,提示我的向量超载。代码如下:
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;