gpt4 book ai didi

c++ - 在 C++ 中连接字符串和数字?

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:26:10 27 4
gpt4 key购买 nike

我正在尝试连接“(”+ mouseX +“,”+ mouseY“)”。但是,mouseX 和 mouseY 是整数,所以我尝试使用如下的字符串流:

std::stringstream pos;
pos << "(" << mouseX << ", " << mouseY << ")";
_glutBitmapString(GLUT_BITMAP_HELVETICA_12, pos.str());

而且它似乎不起作用。

我收到以下错误:

mouse.cpp:75: error: cannot convert std::basic_string<char, std::char_traits<char>, std::allocator<char> >' toconst char*' for argument 2' tovoid _glutBitmapString(void*, const char*)'

我在这个基本的字符串 + 整数连接中做错了什么?

最佳答案

glutBitmapString() 需要一个 char* 而您要向它发送一个字符串。像这样在字符串上使用 .c_str():

_glutBitmapString(GLUT_BITMAP_HELVETICA_12, pos.str().c_str());

关于c++ - 在 C++ 中连接字符串和数字?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/544397/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com