How to Convert wstring to int in C++? Last Updated : 22 Mar, 2024 Summarize Comments Improve Suggest changes Share Like Article 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) Comment More infoAdvertise with us Next Article How to Convert wstring to int in C++? M mguru4c05q Follow Improve Article Tags : C++ Programs C++ cpp-string Practice Tags : CPP Similar Reads How to Convert wstring to double in C++ 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 dou 2 min read How to Convert Float to int in C++? In C++, the float is a short term for floating point value that is used to define numeric values with decimal points. The floating point numbers can be converted to integers using the process called type casting. In this article, we will learn how to convert a float value to an int in C++. Example: 2 min read How to Convert Char Array to Int in C++ In C++, a character array is treated as a sequence of characters also known as a string. Converting a character array into an integer is a common task that can be performed using various methods and in this article, we will learn how to convert char array to int in C++. Example Input:char arr1[] ="1 2 min read How to Read File into String in C++? In C++, file handling allows us to read and write data to an external file from our program. In this article, we will learn how to read a file into a string in C++. Reading Whole File into a C++ StringTo read an entire file line by line and save it into std::string, we can use std::ifstream class to 2 min read Convert Float to String In C++ In this article, we learn how we can convert float to string in C++ using different methods: Using the to_string()Using stringstreamUsing MacrosUsing lexical_cast from the boost library1. Using to_string() The to_string() method takes a single integer variable or other data type and converts it into 3 min read Like