如何转换 int 变量并附加到常量 wchar_t*

How to convert int variable and append to const wchar_t*

本文关键字:常量 wchar 何转换 转换 变量 int      更新时间:2023-10-16

我需要这样的最终查询:
const wchar_t *fin = L"UPDATE info SET status = 'closed' where age = '12'";

如果函数收到一个值,我想附加如下内容:
const wchar_t *fin = L"UPDATE info SET status = 'closed' where age = " + convertedAge;

这是我的更新函数代码:

void updateDB(int passAge){
std::wstring myString;
convertedAge= std::to_wstring(passAge);
const wchar_t* fin = L"UPDATE info SET status = 'closed' where age = " + convertedAge;
}

如何按顺序转换该整数变量,以const wchar_t*附加该整数变量并充当单个查询?

C++标准字符串类包含仅用于此类情况的.c_str()函数。

void updateDB(int passAge){
std::wstring myString = L"UPDATE info SET status = 'closed' where age = '" 
+ std::to_wstring(passAge) + L"'";
const wchar_t* fin = convertedAge.c_str();
}

我终于解决了。我不知道这是否是最好的方法。这是我的代码。

void updateDB(int passAge){
//Convert age to string
std::string q = "'";
std::wstring w;
std::wstring endStr (q.begin(), q.end());
w = endStr;
std::wstring close(L"UPDATE info SET status = 'closed' where age = '");
close += std::to_wstring(passAge);
close += (w);
const wchar_t *finClose = close.c_str();
std::wcout << finClose << std::endl; 
}