Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Another problem with Text  (Read 2962 times)

0 Members and 1 Guest are viewing this topic.

ravenheart

  • Full Member
  • ***
  • Posts: 148
    • View Profile
Another problem with Text
« on: September 16, 2008, 12:35:31 am »
now i want my programm to show the time it is running

i did it something like

Code: [Select]

main()
{
      String Text;
      Text.SetFont(sf::Font::GetDefaultFont());
      Text.SetSize(20);

      Clock Timer;    

      while running
      {
                     events
                     {
                     }
                     Text.SetText(Timer.GetEclapsedTime();  converted to string
                     Draw Text;
      }

}


now i dont want endless strings one after one , i only want ONE text to be shown, showing the current runnig-time

whats my mistake?

ravenheart

  • Full Member
  • ***
  • Posts: 148
    • View Profile
Another problem with Text
« Reply #1 on: September 16, 2008, 01:43:04 am »
oh oh , after thinking bout it i believe i found the answer, with my conversion
osstream out;
 out << blablabla;
string str = out.str();

the string gets longer and longer becasue of out << ,...

well thats not a sfml problem anymore but there was something with ios:flags as solution

ravenheart

  • Full Member
  • ***
  • Posts: 148
    • View Profile
Topic can be deleted
« Reply #2 on: September 16, 2008, 02:03:07 am »
2 mins of googling and i found what i was looking for^^
 ( i´m glad i remember anything since the days i learnd c++ =)

out << seekp(0);

was all i needed to add

sry for spamming

zarka

  • Jr. Member
  • **
  • Posts: 81
    • View Profile
Re: Topic can be deleted
« Reply #3 on: September 16, 2008, 10:01:44 am »
Quote from: "ravenheart"
2 mins of googling and i found what i was looking for^^
 ( i´m glad i remember anything since the days i learnd c++ =)

out << seekp(0);

was all i needed to add

sry for spamming



that shouldn't be necessary ... this is the function i use and it has worked well for quite some time :)
Code: [Select]

template<class T>
std::string ToString(T val)
{
    std::stringstream ss;
    ss << val;
    return ss.str();
}


you can also go the C way
char buf[64];
sprintf(buf, "%d%, val);

but then you need to watch out for buffer overruns and keeping track of what type val actually is .. so the stringstream version is definitely recommended :)
//Zzzarka

 

anything