How to Convert wstring to int in C++? Last Updated : 23 Jul, 2025 Comments Improve Suggest changes 1 Likes Like Report 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;Converting a std::wstring to int in C++To convert a wstring to an integer in C++, we can use the std::stoi function provided in the <string> library that converts a string to an integer. This function also has an overload that accepts a std::wstring. Syntax of std::stoi()stoi(wstr);Here, wstr is the wstring to be converted to int. This function will return the integer value extracted from the string. C++ Program to Convert wstring to intThe below program demonstrates how we can convert a string to int using stoi() function in C++. C++ // C++ program to illustrate how to convert wstring to int #include <iostream> #include <string> using namespace std; int main() { // Creating wstring wstring str = L"12345"; // Converting wstring to int int num = stoi(str); // Print the int cout << "Number: " << num << endl; return 0; } OutputNumber: 12345 Time Complexity: O(N), here N is the size of the string. Auxiliary Space: O(1) Create Quiz Comment M mguru4c05q Follow 1 Improve M mguru4c05q Follow 1 Improve Article Tags : C++ Programs C++ cpp-string Explore C++ BasicsIntroduction to C++3 min readData Types in C++6 min readVariables in C++4 min readOperators in C++9 min readBasic Input / Output in C++3 min readControl flow statements in Programming15+ min readLoops in C++7 min readFunctions in C++8 min readArrays in C++8 min readCore ConceptsPointers and References in C++5 min readnew and delete Operators in C++ For Dynamic Memory5 min readTemplates in C++8 min readStructures, Unions and Enumerations in C++3 min readException Handling in C++12 min readFile Handling in C++8 min readMultithreading in C++8 min readNamespace in C++5 min readOOP in C++Object Oriented Programming in C++8 min readInheritance in C++6 min readPolymorphism in C++5 min readEncapsulation in C++3 min readAbstraction in C++4 min readStandard Template Library(STL)Standard Template Library (STL) in C++3 min readContainers in C++ STL2 min readIterators in C++ STL10 min readC++ STL Algorithm Library3 min readPractice & ProblemsC++ Interview Questions and Answers1 min readC++ Programming Examples4 min read Like