|
urgh Conversion... |
xmltorrent
Member #7,673
August 2006
|
I'm using C++ for my latest game. I'm having problems using the text output functions in Allegro with the std::string type used in C++. For instance this following line of code: textout_ex(screen, font, greg.getName(), 0, 0, makecol(255, 255, 255), -1); Returns this to the compiler: Quote: Invalid type in argument 3. So I decided to cast types: textout_ex(screen, font, static_cast<char>(greg.getName()), 0, 0, makecol(255, 255, 255), -1); And this is what the comiler tells me: Quote: Invaild cast from std::string to char Sounds like a n00b question but I haven't messed with std::string in a while and I'm totally in the dark with it. |
CursedTyrant
Member #7,080
April 2006
|
Assuming that GetName returns a string: textout_ex(screen, font, greg.getName().c_str(), 0, 0, makecol(255, 255, 255), -1); AFAIK you don't cast types using static or dynamic cast. Correct casting would look like this: (char *)greg.getName() ... which in this case would still be incorrect. Of course, I could be wrong, as I've only used dynamic_cast, and never static_cast. --------- |
OICW
Member #4,069
November 2003
|
In that case you need a pointer, but that string is static, besides you cannot retype string to embeded type. As CursedTyrant said, you have to use string member function c_str() to make it work. [My website][CppReference][Pixelate][Allegators worldwide][Who's online] |
|