Specific strings and numbers in C ++?

I am trying to execute concat "(" + mouseX + "," + mouseY ")". However, mouseX and mouseY are ints, so I tried using a string stream as follows:

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

And it does not work.

I get the following error:

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

What am I doing wrong in this base chain + integer concatenation?

+4
source share
2 answers

glutBitmapString() expects a char* , and you send it a string. use .c_str () in a line like this:

 _glutBitmapString(GLUT_BITMAP_HELVETICA_12, pos.str().c_str()); 
+5
source

Try

 _glutBitmapString(GLUT_BITMAP_HELVETICA_12, pos.str().c_str()); 
+3
source

All Articles