Cześć, zacząłem się wdrażać w bibliotekę SFML i nie mogę dojść jak mogę wyświetlić liczbę lub inne typy w postaci text-u.
Klasa Text w konstruktorze przyjmuje tylko wartość typu sf::String. Jak mogę rzutować jakąś liczbę na sf::String-a?
Chodzi mi o to, że chciałbym wyświetlić wynik metody clock.GetElapsedTime().
Czy może mi ktoś w tym pomóc?
z góry dzięki.
0
0
http://sfml-dev.org/documentation/2.0/classsf_1_1String.php
Z tego co tu pisze, to wystarczy, że przekażesz std::string do konstruktora.
Ponadto:
sf::String s;
std::string s1 = s; // automatically converted to ANSI string
std::wstring s2 = s; // automatically converted to wide string
s = "hello"; // automatically converted from ANSI string
s = L"hello"; // automatically converted from wide string
s += 'a'; // automatically converted from ANSI string
s += L'a'; // automatically converted from wide string
0
Dzięki, ale jak przekonwertować sf::Time, którą zwraca funkcja getElapsedTime() na String? Lub chociaż na int?
0
#include <stringstream>
#include <Time.hpp>
#include <Clock.hpp>
template<class T>
String toString(T var) {
ostringstream oss;
oss << var;
return oss.str();
}
int main() {
Clock clock;
Time t = clock.getElapsedTime();
String str = toString(t.asSeconds());
return 0;
}
Pisane z palca, sprawdz czy dziala.