1 2 3 4 5 6 7 8 9 10 11 12
|
#include <string>
#include <sstream>
#include <iostream>
int main()
{
double Accountbalance = 47.50;
std::ostringstream oss;
if (oss << Accountbalance)
std::string s = oss.str(); // conversion successful.
else
// handle conversion error.
}
|
The conversion happens during the << operator, which is why its return value is checked.
If the conversion fails, it will not go into the if.
Last edited on