如何在函数中将字符串和分数存储为(Int 或 float)

How to store String and score as (Int or float) in Function

本文关键字:存储 Int float 函数 字符串      更新时间:2023-10-16

>CODE

void DrawString(float x, float y, const string& score, float * color)
void DrawString(60, 250, "SCORE =" &score, scolor)

混乱

我得到的是第一个参数采用 x 坐标,第二个参数采用 y 坐标,我弄乱了第三个参数,我必须并排获取字符串和整数。

如何取这样的值?

您有 2 个选项。

第一种是取字符串变量本身:

DrawString(60, 250, score, scolor);

第二种方法是将字符串文本传递给函数:

DrawString(60, 250, "SCORE =", scolor);

如果要连接这两个字符串,可以使用选项 1,如下所示:

std::string tmp = "SCORE = " + score;
DrawString(60, 250, tmp, scolor);

此外,调用函数时无需使用void关键字。事实上,我认为这会适得其反。我已经相应地更新了我的答案。

相关文章: