Q:

Using wcstod to convert zero value

Am using wcstod() to convert to numeric type text data which I read from an XML file:
double x;
BSTR name;
MSXML::IXMLDOMNodeListPtr theList;
MSXML::IXMLDOMNodePtr theItem;

//Some XML API here...

theItem = theList->Getitem(0);
theItem->get_text(&name);
x = wcstod(name,NULL);

the problem is that this function returns NULL upon failure, but sometimes I do want to read and convert the valid string L"0". 
Is there a workaround for this? 

A:

You can use std::stod which will throw exception if the function fails. 
Make sure BSTR is initialized to NULL. Add error check for Getitem and get_text
#include <string>

BSTR name = nullptr;
...
double x = 0;
if(name)
{
    try
    {
        x = std::stod(name);
    }
    catch(...)
    {
        //error ...
    }
}

