Couldn't find an answer for following question:
I'm new to C++ and am doing some tests now. I'm using std::fixed and std::setprecision functions to get a decimal number with 5 zeros. This works using cout, but i have no idea how to assigning the results to a variable instead of printing them using cout.
//Works
int fetchJD(std::string str) {
std::cout << std::fixed << std::setprecision(0) << str;
return 0;
}
I tried things like using sstream but whenever i try to assign the results to another string so i can return the results, lets the compiler fails.
// Not working
int fetchJD(std::string str)
{
std::stringstream ss;
string temp;
ss << std::fixed << std::setprecision(0) << str;
temp = ss.str();
return temp;
}
Which results in the compiler as error:
In function ‘int fetchJD(std::__cxx11::string)’:
astroapp.cpp:43:12: error: cannot convert ‘std::__cxx11::string {aka
std::__cxx11::basic_string<char>}’ to ‘int’ in return
return temp;
So how can i pass the results from std::fixed << std::setprecision(0) << str; into another string?