I presume this to be very simple but I cannot get it to work.
I am simply trying to convert a std::wstring to an int.
I have tried two methods so far.
The first is to use the "C" method with "atoi" like so:
int ConvertedInteger = atoi(OrigWString.c_str());
However, VC++ 2013 tells me:
Error, argument of type "const wchar_t *" is incompatable with parameter of type "const char_t *"
So my second method was to use this, per Google search:
std::wistringstream win(L"10");
int ConvertedInteger;
if (win >> ConvertedInteger && win.eof())
{
// The eof ensures all stream was processed and
// prevents acccepting "10abc" as valid ints.
}
However VC++ 2013 tells me this:
"Error: incomplete type not allowed."
What am I doing wrong here?
Is there a better way to convert a std::wstring to int and back?
Thank you for your time.
#include <sstream>? Your code with the stringstream should work. - Praetorianint ConvertedInteger = _wtoi(OrigWString);... - A Bstd::stringfrom the string and usestd::stoion that. You might incur a memory allocation if the number is big enough, but I doubt it's any worse than using stringstreams. - Stuart Olsen#include <istream>is required forwistringstream- M.M