我正在尝试连接“(”+ 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> >' to
const char*' for argument2' to
void _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/