C++中的Concat字符串和数字?

Kin*_*tor 4 c++ string

我试图连续"("+ + mouseX +","+ mouseY")".但是,mouseX和mouseY是整数,所以我尝试使用stringstream,如下所示:

std::stringstream pos;
pos << "(" <<  mouseX << ", " << mouseY << ")";
_glutBitmapString(GLUT_BITMAP_HELVETICA_12, pos.str());
Run Code Online (Sandbox Code Playgroud)

它似乎不起作用.

我收到以下错误:

mouse.cpp:75:错误:无法转换std::basic_string<char, std::char_traits<char>, std::allocator<char> >' toconst char*'参数2' tovoid _glutBitmapString(void*,const char*)'

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

sho*_*osh 5

glutBitmapString()期待一个char*,你发送一个字符串.像这样在字符串上使用.c_str():

_glutBitmapString(GLUT_BITMAP_HELVETICA_12, pos.str().c_str());
Run Code Online (Sandbox Code Playgroud)