# Allegro - Printing X & Y coordinates to the screen

This topic is 2517 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello forum, right now I'm challenging myself to make a good allegro basic circle movement without any tutorials .
So there is one thing that I want to implement into my code and that is, printing the x and y coordinates to the screen. For multiple purposes .

I tried the textout but I really don't know how to make the program print the variable , here is what I tried.

 textout(buffer, font, "this is x" << x , "this is y" << y , 0, 0, makecol(0, 250, 30) , -1); 

##### Share on other sites

I tried the textout but I really don't know how to make the program print the variable , here is what I tried.
 textout(buffer, font, "this is x" << x , "this is y" << y , 0, 0, makecol(0, 250, 30) , -1); 1--^ 2--^ (3) 4--^ 5-^ 

1) A c-string isn't a stream. In C and C++, one cannot concatenate strings natively. One must either use strcat/sprintf (C) or stringstreams (C++)
2) The comma operator separates parameters, this means the compiler is expecting an integer for (3)
3) The compiler expects an integer for the fourth parameter
4) A c-string isn't a stream.
5) Because of the extra parameter at (2), this is treated as an extra parameter.

What you want to do is use stringstreams:

 #include <sstream> stringstream ss; ss << "x=" << x << ", " << "y=" << y; string temp = ss.str(); textout( buffer, font, temp.c_str(), 0, 0, makecol( 0, 250, 30 ), -1 ); 

1. 1
Rutin
24
2. 2
3. 3
JoeJ
18
4. 4
5. 5

• 38
• 23
• 13
• 13
• 17
• ### Forum Statistics

• Total Topics
631706
• Total Posts
3001832
×