I'm working on a project for school and we just found out that outtextxy()
(a function from graphics.h, which we must use) requires as the text parameter a char array.
Here is it's declaration: void outtextxy (int x, int y, char *textstring)
The issue is that we need to print out a number of type double
, including the decimal point. I have previously tried making it work using knowledge from other similar questions, but none has worked.
Here are is my latest attempt, which resulted in a Segmentation Fault:
char *DoubleToString(long double x)
{
char s[256]="00";
std::ostringstream strs;
strs << x;
string ss = strs.str();
for(int i=0; i < ss.length(); i++)
s[i] = ss[i];
return s;
}
NOTE: I am still somewhat new to programming and I don't exactly know what ostringstream
and the bitshift-looking operation are doing, but I tried to copy-paste that part in hopes of it working.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…