SFML community forums
Help => General => Topic started by: ravenheart on September 18, 2008, 06:28:22 pm
-
hello , i got a float and want to display it in the form numbers. XX
i did it this way:
float score = Spieluhr.GetElapsedTime();
out2.setf(ios::precision(2)) << Spieluhr.GetElapsedTime() ;
str2 = out2.str();
Text.SetText(str2);
out2.seekp(0) ;
out is a sstream, out << setprecision(2) doesnt work, too
Text is a String
-
out << setprecision(2) << fixed << score;
-
well now same again it seems:
C:\Users\Isis\Documents\C++\MEINS\Pong_new\main.cpp||In function `int main()':|
C:\Users\Isis\Documents\C++\MEINS\Pong_new\main.cpp|180|error: `[color=darkred]setprecision[/color]' was not declared in this scope|
C:\Users\Isis\Documents\C++\MEINS\Pong_new\main.cpp|180|warning: unused variable 'setprecision'|
||=== Build finished: 1 errors, 1 warnings ===|
-
it seems sstreams dont have setprecision
-
It's in header <iomanip> and namespace std.
#include <iomanip>
#include <sstream>
std::ostringstream out;
float score = 0.1234567f;
out << std::setprecision(2) << std::fixed << score;
-
well now that works, but now i have another prblem:
in out there is the current score, when a new game is started
the timer is at 0.00, when the game befor had lets say 111.11 s, then
in the new game 0.0011 is shown because i only use out.seekp(0) to get new data in it how can i clear a ostringstream ?
-
oss.str("");
-
so i can modify the content of the stream and force it to be anything i want?
i thought its only to get what is already in it ^^
but now it works fine , thank you
=============================
as u see there are many beginners questions
not really related to sfml thats because i learn
c++ by myself and only java at university
thanks again =)
-
well now that works, but now i have another prblem:
in out there is the current score, when a new game is started
the timer is at 0.00, when the game befor had lets say 111.11 s, then
in the new game 0.0011 is shown because i only use out.seekp(0) to get new data in it how can i clear a ostringstream ?
you could also create new stringstreams every time :) ..
int main()
{
float myval = 0.5f;
std::string myval_str;
{
std::stringstream ss;
ss << myval;
myval_str = ss.str();
}
}
scopes can have their uses :)