You can use a std::wostringstream
to achieve this.
wchar_t* getStuff(const double *arr, const int arr_size)
{
std::vector<wchar_t> result(arr_size*2);
for( int i = 0; i < arr_size*2; i++)
{
std::wostringstream theStringRepresentation;
theStringRepresentation << arr[i];
// use theStringRepresentation.str() in the following code to refer to the
// widechar string representation of the double value from arr[i]
}
return &result[0];
}
Also note that returning a local scope variable reference is undefined behavior!
return &result[0]; // Don't do this!
Why not simply using a std::vector<std::wstring>
instead of the std::vector<wchar_t>
?
std::wstring getStuff(const double *arr, const int arr_size) {
std::vector<std::wstring> result(arr_size*2);
for( int i = 0; i < arr_size*2; i++)
{
std::wostringstream theStringRepresentation;
theStringRepresentation << arr[i];
// use theStringRepresentation.str() in the following code to refer to the
// widechar string representation of the double value from arr[i]
}
return result[0];
}