[C++/SDL2] Print score with 6 spots

Hi Folks,

Still at my platformer ^^. I'm going very Super-Mario-Bros like, and the stats are not to be left away x).

I didnt Encounter any Problems with printing the actual score, but I'd like to Format it.

I want it to have always six spots not depending on the current score.

So if my score was 0, it should be 000000.
So if my score was 1000, it should be 001000

Any suggestions? I'm working with strings and stringstream...

EDIT: Here is how I'm loading updating the Score
1
2
3
4
    m_Score++;
    std::stringstream ss;
    ss << m_Score;
    sScore = ss.str().c_str();


This is the way my score is loaded. The m_Score++ is just to test whether it updates correctly
Last edited on
You can set the width of the output by using std::setw, and to get zeroes on the left instead of spaces you can use std::setfill.

 
ss << std::setw(6) << std::setfill('0') << m_Score;
Wow, sometimes its impressive how much of a *&?/; i am ^^'

Anyway, thats exactly what I've been searching for! :DD

After #include <iomanip> I got it working :) Thanks Peter
Topic archived. No new replies allowed.