![]() |
VOOZH | about |
In C++, std::wstring is a type of string where each character is of a wide character type. These types of strings can be used to store the numerical strings which can then be converted to their corresponding type. In this article, we will see how to convert a wstring to an int in C++.
Input: wstr = L"12345"; Output: int num = 12345;
To convert a wstringto an integer in C++, we can use the std::stoifunction provided in the <string> library that converts a string to an integer. This function also has an overload that accepts a std::wstring.
stoi(wstr);Here, wstr is the wstring to be converted to int. This function will return the integer value extracted from the string.
The below program demonstrates how we can convert a string to int using stoi() function in C++.
Number: 12345
Time Complexity: O(N), here N is the size of the string.
Auxiliary Space: O(1)