|
|
|
#1 |
|
Messages: n/a
Hébergeur: |
On Tue, 2008-01-15 at 11:15 -0800, rob.ahlberg@gmail.com wrote: > I got an integer what I trying to use with allegro function > textout_ex() but it wants an char[]/char* as arg... And I really don't > know how to cast it to one... You don't cast your int, you convert it. #include <sstream> #include <ostream> .... std: stringstream s;s << my_int; textout_ex(..., s.str().c_str(), ...); or, if the allegro textout_ex function barfs due to something about "const", try: #include <vector> #include <sstream> #include <ostream> .... std: stringstream s;s << my_int; std::vector<char> v(s.str().begin(), s.str().end()); v.push_back('\0'); textout_ex(..., &v[0], ...); // &v[0] is okay because v.size() >= 1 -- Tristan Wibberley Any opinion expressed is mine (or else I'm playing devils advocate for the sake of a good argument). My employer had nothing to do with this communication. |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
On 15 Jan, 20:35, Tristan Wibberley <maihem-...@maihem.org> wrote:
> On Tue, 2008-01-15 at 11:15 -0800, rob.ahlb...@gmail.com wrote: > > I got an integer what I trying to use with allegro function > > textout_ex() but it wants an char[]/char* as arg... And I really don't > > know how to cast it to one... > > You don't cast your int, you convert it. > > #include <sstream> > #include <ostream> > > ... > > std: stringstream s;> s << my_int; > textout_ex(..., s.str().c_str(), ...); > > or, if the allegro textout_ex function barfs due to something about > "const", try: > > #include <vector> > #include <sstream> > #include <ostream> > > ... > > std: stringstream s;> s << my_int; > std::vector<char> v(s.str().begin(), s.str().end()); > v.push_back('\0'); > textout_ex(..., &v[0], ...); // &v[0] is okay because v.size() >= 1 > > -- > Tristan Wibberley > > Any opinion expressed is mine (or else I'm playing devils advocate for > the sake of a good argument). My employer had nothing to do with this > communication. Yeah the programming guru at my school ed me with the string stream. Unfortunately I cannot clear the string.. It's a little game I'm currently at.. And I got a function to determine the fps.Then I got 'int fps' And I do like: ss << fps; print(ss.str().c_str()); ss.flush(); But that's the problem... It wont clear the string. It just add the new fps after the other one and so on. I need to clear it... |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
rob.ahlberg@gmail.com wrote:
> [..] > Yeah the programming guru at my school ed me with the string > stream. Unfortunately I cannot clear the string.. It's a little game > I'm currently at.. And I got a function to determine the fps.Then I > got 'int fps' And I do like: > ss << fps; > print(ss.str().c_str()); > ss.flush(); > But that's the problem... It wont clear the string. It just add the > new fps after the other one and so on. I need to clear it... This should clear the stream, IIRC: ss.str().clear(); V -- Please remove capital 'A's when replying by e-mail I do not respond to top-posted replies, please don't ask |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
On Jan 16, 12:05 am, "Victor Bazarov" <v.Abaza...@comAcast.net> wrote:
> rob.ahlb...@gmail.com wrote: > > [..] > > Yeah the programming guru at my school ed me with the string > > stream. Unfortunately I cannot clear the string.. It's a little game > > I'm currently at.. And I got a function to determine the fps.Then I > > got 'int fps' And I do like: > > ss << fps; > > print(ss.str().c_str()); > > ss.flush(); > > But that's the problem... It wont clear the string. It just add the > > new fps after the other one and so on. I need to clear it... > This should clear the stream, IIRC: > ss.str().clear(); I don't see how. stringstream::str() returns by value; calling a member function on the temporary it returns can't have any effect on the stream itself. There is a non const version of str(): ss.str( std::string() ) ; which would do the job, but frankly, the real solution is much simpler: if you want a new ostringstream, use a new ostringstream. (This is the sort of code which would be in a function anyway, with the ostringstream as a local variable. So each time you call the function, you get a new instance.) -- James Kanze (GABI Software) email:james.kanze@gmail.com Conseils en informatique orientée objet/ Beratung in objektorientierter Datenverarbeitung 9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34 |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
On 16 Jan, 00:05, "Victor Bazarov" <v.Abaza...@comAcast.net> wrote:
> rob.ahlb...@gmail.com wrote: > > [..] > > Yeah the programming guru at my school ed me with the string > > stream. Unfortunately I cannot clear the string.. It's a little game > > I'm currently at.. And I got a function to determine the fps.Then I > > got 'int fps' And I do like: > > ss << fps; > > print(ss.str().c_str()); > > ss.flush(); > > But that's the problem... It wont clear the string. It just add the > > new fps after the other one and so on. I need to clear it... > > This should clear the stream, IIRC: > > ss.str().clear(); > > V > -- > Please remove capital 'A's when replying by e-mail > I do not respond to top-posted replies, please don't ask Aha.. I just wroted ss.clear(); Thanks for the ![]() |
|
|
|
#6 |
|
Messages: n/a
Hébergeur: |
rob.ahlberg@gmail.com wrote:
> On 16 Jan, 00:05, "Victor Bazarov" <v.Abaza...@comAcast.net> wrote: >> rob.ahlb...@gmail.com wrote: >>> [..] >>> Yeah the programming guru at my school ed me with the string >>> stream. Unfortunately I cannot clear the string.. It's a little game >>> I'm currently at.. And I got a function to determine the fps.Then I >>> got 'int fps' And I do like: >>> ss << fps; >>> print(ss.str().c_str()); >>> ss.flush(); >>> But that's the problem... It wont clear the string. It just add the >>> new fps after the other one and so on. I need to clear it... >> >> This should clear the stream, IIRC: >> >> ss.str().clear(); >> >> V >> -- >> Please remove capital 'A's when replying by e-mail >> I do not respond to top-posted replies, please don't ask > > Aha.. I just wroted ss.clear(); > Thanks for the ![]() You probably need to do 'ss.clear()' as well, in case there are any error bits set... V -- Please remove capital 'A's when replying by e-mail I do not respond to top-posted replies, please don't ask |
|
![]() |
| Outils de la discussion | |
|
|