如何在函数中将字符串和分数存储为(Int 或 float)
How to store String and score as (Int or float) in Function
>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
关键字。事实上,我认为这会适得其反。我已经相应地更新了我的答案。
相关文章:
- 如何在cpp.中使用协议缓冲区存储大缓冲区/数组(char/int)
- 在c++中获取两个大int,并将它们存储在数组中
- 在 std::无符号字符的向量处存储 int 的十六进制表示形式
- 如果 x < 10,则添加前导 0 并将其存储为 int
- 如何读取 TXT 文件并仅将 int 存储在 C 中
- 如何在函数中将字符串和分数存储为(Int 或 float)
- 如何声明一个必须在C++中同时存储int和char值的2D数组
- 如果char可以在C++中存储数字,为什么我们需要int
- 如果我在 C++ 中为 int 提供双精度,输入缓冲区中存储了什么?
- 我应该使用无符号字符而不是 int 来存储永远不会大于 255 的值吗?
- 我正在编写一个代码来将 int 数组存储在文件中,然后用 c++ 检索它,但是检索第一项是假值,我该如何解决这个问题?
- unordered_set是否适合存储矢量<int>元素的数据结构?如果是这样,我将如何实现哈希函数?
- 什么是在C 中存储结果INT*的最佳数据类型
- char*中存储的返回int值(0-255)给出了负值
- 将字符指针按顺序存储在 map 中 std::map<char*, int> mymap。将其存储为字符或字符串不是一个选项
- 如何在文件中节省空间地存储和检索 std::vector<int> 值
- 将INT和STR输入并将它们存储到两个单独的列表中
- 如何在单个变量中同时存储 int 或字符串,而不会丢失它们的类型
- 在数组中存储 int 的各个数字
- 如何将 void 指针类型转换为 int 指针,然后在其中存储 int