|
-
Feb 22nd, 2002, 10:51 PM
#1
Thread Starter
Fanatic Member
convert float to string
Code:
char *output="fps=";
char tmp[20];
strcat(output,itoa((int)fps,tmp,2));
that's my code, but my program always locks up at the "strcat" section. fps is a float, which i typecasted cuz of "possible loss of data"...see any problems?
I'm trying to get a string that says "FPS=<fps>", but it won't work
Visit www.fragblast.com
Gaming, forums, and a online RPG/Battle system
(__Flagg) DOT NET? is this a Hindi Dating service?
-
Feb 22nd, 2002, 11:01 PM
#2
Thread Starter
Fanatic Member
nevermind, i used sprintf()
Visit www.fragblast.com
Gaming, forums, and a online RPG/Battle system
(__Flagg) DOT NET? is this a Hindi Dating service?
-
Feb 24th, 2002, 06:08 PM
#3
Monday Morning Lunatic
In pure C++:
Code:
ostringstream oss;
oss << "FPS: " << fps_value;
// Do something with oss.str()
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Feb 24th, 2002, 06:16 PM
#4
Thread Starter
Fanatic Member
I'm outputting it to a window i created with CreateWindow()
Visit www.fragblast.com
Gaming, forums, and a online RPG/Battle system
(__Flagg) DOT NET? is this a Hindi Dating service?
-
Feb 24th, 2002, 06:20 PM
#5
Monday Morning Lunatic
Code:
DrawText(hDC, oss.str().c_str(), ...);
...or something
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Feb 24th, 2002, 06:26 PM
#6
Thread Starter
Fanatic Member
i think it was textout..yeah here it is:
Code:
char *output=new char[];
sprintf(output,"FPS=%f",fps);
TextOut(hDC,10,10,output,strlen(output));
The thing was i had it output every second, and it showed up for a split second then disappeared...adn reappeared every other second...confusing but yeah.
Then I outputed it in the DrawGL() section, and it did the same thing here
Visit www.fragblast.com
Gaming, forums, and a online RPG/Battle system
(__Flagg) DOT NET? is this a Hindi Dating service?
-
Feb 24th, 2002, 06:28 PM
#7
Monday Morning Lunatic
Code:
char *output=new char[];
Uh... 
Not sure how that one can work...
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Feb 24th, 2002, 06:30 PM
#8
Thread Starter
Fanatic Member
Hey I don't know either...I just know it works.
Should I use
Code:
char *output = (char *)malloc(255*sizeof(char));
instead? I've used that for a while without any problem, so I just stuck with it.
Or do you mean "why does it work he didn't specify a max size"?
Visit www.fragblast.com
Gaming, forums, and a online RPG/Battle system
(__Flagg) DOT NET? is this a Hindi Dating service?
-
Feb 24th, 2002, 06:34 PM
#9
Monday Morning Lunatic
I'm just intrigued as to what size buffer you get when you don't give a size - I expect it's compiler dependent.
In C++, use new:
Code:
char *buffer = new char[255];
I'd still use the stringstreams one though, safer and more c++-like (probably just as fast as well, if not faster).
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Feb 24th, 2002, 06:41 PM
#10
Thread Starter
Fanatic Member
I'm using VC++ 6.0
It doesn't just return 6? (FPS=30) (example)
I'll do a quick thing to check
Visit www.fragblast.com
Gaming, forums, and a online RPG/Battle system
(__Flagg) DOT NET? is this a Hindi Dating service?
-
Feb 24th, 2002, 06:43 PM
#11
Thread Starter
Fanatic Member
Yup, I just did quick test, since the number was a float, it came out as
85.00000
so strlen() was 12
Visit www.fragblast.com
Gaming, forums, and a online RPG/Battle system
(__Flagg) DOT NET? is this a Hindi Dating service?
-
Feb 25th, 2002, 12:04 PM
#12
Monday Morning Lunatic
Before you insert the float, try something like oss.precision(2);.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Feb 25th, 2002, 03:07 PM
#13
Thread Starter
Fanatic Member
ok thanks
what's oss?
i think i'll change it to an int...i dont think the fps will go above 32000 (or whatever the max # for int is)
Visit www.fragblast.com
Gaming, forums, and a online RPG/Battle system
(__Flagg) DOT NET? is this a Hindi Dating service?
-
Feb 25th, 2002, 05:31 PM
#14
Monday Morning Lunatic
oss is the ostringstream object from earlier.
The maximum value of an int is about 2 thousand million (4 for unsigned).
Basically, anything you can do to a stream like cout or cin, you can do to a stringstream...that's what makes them so utterly cool
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Feb 25th, 2002, 05:34 PM
#15
Thread Starter
Fanatic Member
Ah. And that works for printf() and scanf()?
Visit www.fragblast.com
Gaming, forums, and a online RPG/Battle system
(__Flagg) DOT NET? is this a Hindi Dating service?
-
Feb 25th, 2002, 05:43 PM
#16
Monday Morning Lunatic
I don't think they're particularly compatible with each other, but they do more or less the same thing.
Basically, as printf, scanf, sprintf, sscanf all use a format string, cout, cin, ostringstream, istringstream all use the same manipulators.
For example, if you define operator>> for your class, then it will work with a stringstream
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Feb 25th, 2002, 05:47 PM
#17
Thread Starter
Fanatic Member
<-- C++ n00b
"Basically, as printf, scanf, sprintf, sscanf all use a format string, cout, cin, ostringstream, istringstream all use the same manipulators.
For example, if you define operator>> for your class, then it will work with a stringstream"
Visit www.fragblast.com
Gaming, forums, and a online RPG/Battle system
(__Flagg) DOT NET? is this a Hindi Dating service?
-
Feb 25th, 2002, 05:51 PM
#18
Monday Morning Lunatic
Ok.
Code:
printf("Hello: %d\n", int_value_here);
cout << "Hello: " << int_value_here << endl;
...or...
Code:
void thingie(ostream &os) {
os << 56 << hex << 255 << endl;
}
void somecode() {
thingie(cout);
ostringstream oss;
thingie(oss);
cout << oss.str();
}
All the streams work in the same way, and are interchangeable at the ostream / istream level.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Feb 26th, 2002, 02:53 PM
#19
Thread Starter
Fanatic Member
Ohh okay I get it...Thanks
Visit www.fragblast.com
Gaming, forums, and a online RPG/Battle system
(__Flagg) DOT NET? is this a Hindi Dating service?
-
Feb 26th, 2002, 02:57 PM
#20
Monday Morning Lunatic
No problem.
When you think about it, it's far more logical than C's approach.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Feb 26th, 2002, 03:02 PM
#21
Thread Starter
Fanatic Member
yeah, you can customize it alot easier with less code.
Me think's ill use that somewhere...
Visit www.fragblast.com
Gaming, forums, and a online RPG/Battle system
(__Flagg) DOT NET? is this a Hindi Dating service?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|