compiler error when trying to show text using winbgi

219 views Asked by At

I have a string that I want to show on the winbgi window using outtextxy.

The problem is outtextxy only takes the pointer of a char array which shows a compiler error.

Here is the code

for(int i=0;i<13;i++){
        setcolor(RED);
        circle(otab[i].x1,otab[i].y1,otab[i].radius);
        string txt="obs";
        txt.append(1,i);
        outtextxy(otab[i].x1,otab[i].y1,txt);
}

2

There are 2 answers

4
on8tom On BEST ANSWER

if string is a std::string, use txt.c_str()

https://www.cplusplus.com/reference/string/string/c_str/

1
AidenFive On

thanks everyone for the answers. here is the updated code.

    for(int i=0;i<13;i++){
        setcolor(RED);
        circle(otab[i].x1,otab[i].y1,otab[i].radius);
        string txt="obs:";
        std::ostringstream oss;//i used ostringstream because append didn't work properly
        oss << txt << i;
        string pl=oss.str(); 
        outtextxy(otab[i].x1,otab[i].y1,(char*)pl.c_str());
    }