Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
370 views
in Technique[技术] by (71.8m points)

c++ - 如何修复输出错误字符串和整数混合(How to fix output error String and int mixing)

QUESTION (题)

I am trying to update the score after each iteration in my display.

(我试图在显示屏上的每次迭代后更新分数。)

How to do so with The following Function.

(如何使用以下功能。)

Code (码)

void DrawString(int x, int y, int width, int height,const string &score,
float*color) {
    float fx = (float)x / width * 2 - 1, fy = (float)y / height * 2 - 1;
    DrawString(fx, fy, score, color);
}
// Function draws a string at given x,y coordinates
void DrawString(float x, float y, const string& score, float * color) {
    glPushMatrix();
    glLoadIdentity();
    glDisable(GL_TEXTURE_2D);
    glBindTexture(GL_TEXTURE_2D, 0);

    GLvoid *font_style = GLUT_BITMAP_TIMES_ROMAN_24;
    if (color)
        glColor3fv(color);
    glRasterPos3f(x, y, 1);
    //  Draw the characters one by one
    for (int i = 0; i < score.size(); i++)
        glutBitmapCharacter(font_style, score[i]);
    glPopMatrix();
}

int main(){
    int score = 45;
    DrawString(250,650,"score : " + score ,colors[RED]);
    //EXAMPLE
    score++;

ERROR (错误)

error: invalid operands of types 'const char [9]' and 'float' to binary 'operator+'

(错误:类型为'const char [9]'和'float'的类型为二进制'operator +'的无效操作数)

DrawString(250,650,"score : " + score,colors[RED]);

(DrawString(250,650,“ score:” + score,colors [RED]);)

  ask by TechJuice02 translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.9k users

...