![]() |
|
Textprint_ex and strings |
Raf Vermeulen
Member #7,166
April 2006
|
Hey, I'm trying to print a string using textprint_ex, but whenever I get to the line of code that does that, the program crashes. The string itself shows fine in a console window when doing cout. The line of code I use, is this: Anybody knows why it crashes, and how to fix it? |
Kauhiz
Member #4,798
July 2004
|
Let's see some more code. --- |
Raf Vermeulen
Member #7,166
April 2006
|
When I comment out the textprintf_ex command, it all works smoothly, but with that command, it crashes. |
Kauhiz
Member #4,798
July 2004
|
That's because textprintf_ex wants a C-string, not a std::string. I'm surprised that even compiles. --- |
X-G
Member #856
December 2000
![]() |
It compiles because variadic functions don't typecheck "..." arguments. -- |
Kauhiz
Member #4,798
July 2004
|
Good to know. --- |
HoHo
Member #4,534
April 2004
![]() |
instead of test use test.c_str() __________ |
Raf Vermeulen
Member #7,166
April 2006
|
That works like a charm, the .c_str():D Thanks for the help! |
Kikaru
Member #7,616
August 2006
![]() |
.c_str() returns a char array (C-style string) just like the string you used it on. Just felt the need to point that out. |
Kitty Cat
Member #2,815
October 2002
![]() |
Quote: It compiles because variadic functions don't typecheck "..." arguments.
It does if you add the printf attribute to the function. So either MSVC doesn't have a way to check it and he's using MSVC, or he has warnings off. -- |
Raf Vermeulen
Member #7,166
April 2006
|
Warnings're turned on. Compiler's standard one in Dev-C++ (with the Allegro parameter). |
Neil Black
Member #7,867
October 2006
![]() |
Figuring out how to print strings got me so frustrated. I still have no idea where anyone could find out they had to add .c_str() to their string variable. I'm just glad someone on the forums knew.
|
GullRaDriel
Member #3,861
September 2003
![]() |
Possumdude0 said: I still have no idea where anyone could find out they had to add .c_str() to their string variable. Google is your friend. Or your favorite porn search engine . "Code is like shit - it only smells if it is not yours" |
Neil Black
Member #7,867
October 2006
![]() |
GullRaDriel: wow, you've answered almost every one of my posts today!
|
gnolam
Member #2,030
March 2002
![]() |
Quote: I still have no idea where anyone could find out they had to add .c_str() to their string variable. From wherever you were supposed to have learned C++. -- |
Neil Black
Member #7,867
October 2006
![]() |
I learned C++ from gamedev.net, and a little right here.
|
HoHo
Member #4,534
April 2004
![]() |
Get a good free C++ book. I learnt about .c_str() from the one that should be on the first link, "thinking in C++" by Bruce Eckel. __________ |
GullRaDriel
Member #3,861
September 2003
![]() |
Possumdude0: It's because I got nothing else to do today. I second HoHo and Gnolam thought. "Code is like shit - it only smells if it is not yours" |
|