VOOZH about

URL: https://www.geeksforgeeks.org/cpp/convert-wstring-to-double-in-c/

⇱ How to Convert wstring to double in C++ - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

How to Convert wstring to double in C++

Last Updated : 23 Jul, 2025

In C++, std::wstring is a type of string where each character is of a wide character type. Converting wstring to a double in C++ can be a common requirement especially when dealing with the inputs that are stored as unicode characters. In this article, we will learn how to convert a wstring to a double in C++.

Example

Input:
wstring input = L"3.14159"

Output:
Converted double value is: 3.14159

Converting wstring to double in C++

To convert a also known as wide string to a in C++, we can use the function provided by the . This function takes a string or wstring as input and returns the corresponding double value.

Syntax to Use std::stod

stod(wstring(str.begin(),str.end()));

Here,

  • str denotes the name of the input wide string.
  • str.begin() is an pointing to the first character of the given wide string.
  • str.end() is an iterator pointing to the end of the given wide string.

C++ program to Convert a wstring to double

The following program illustrates how we can convert a wstring to a double value in C++.


Output

Converted double value: 3.15159
Type of result: d

Time Complexity: O(N), here N is the length of the wide string.
Auxiliary Space: O(1)

Comment
Article Tags: