Q:

How to convert a string into a long double?

To start off, I have thoroughly examined other questions on that matter and nothing helped me. I need to convert a string into a long double type, and nothing works for me.
string a="634.232";
long double x;
x=strtold(a.c_str(),0);

For example: this "strtold" changes this input into this output.

A:

Check for errors:
#include <cerrno>
#include <cstdlib>
#include <iostream>

const char str[] = "634.232";

int main()
{
    char * e;
    errno = 0;
    long double val = std::strtold(str, &e);

    if (*e != '\0' || errno != 0) { /* error */ std::abort(); }

    std::cout << "SUccessfully parsed: " << val;
}

Note that string parsing can fail in multiple ways: The string may not, or not in its entirety, represent a number, or the number that it does represent may be too large to fit into the data type. You have to check for all those possibilities, which is what this code is doing. The end pointer e checks that we've consumed the entire string, and the errno checks that the conversion succeeded.

