|
-
Sep 9th, 2002, 03:24 AM
#1
Thread Starter
Lively Member
float array to string - urgent!!!
All,
I have an array of 8 floating point numbers which i need to convert to a string so that i can send it over a network so my VB front end can read it.
How do i convert the floats to a string??
Need to get this sorted quick....been struggling with it for 2 days now
Matt
-
Sep 9th, 2002, 04:06 AM
#2
C:
sprintf
%f is a floating var.
C++:
ostringstream
in the header <sstream>
use it like any other stream (cout, ofstream)
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Sep 9th, 2002, 04:34 AM
#3
Thread Starter
Lively Member
Im not actually printing them to screen.....i need to convert the floats to one big string and then write them character by character across the network...
Matt
-
Sep 9th, 2002, 05:33 AM
#4
printf prints to the screen.
sprintf prints to a string
ostream prints to the stream
ostringstream prints to a string
I know what I'm talking about.
Code:
#include <sstream>
using std::ostringstream;
float arF[10];
void Convert(float *arF, int len, std::string &str)
{
ostringstream ss;
for(float *p = arF; p < arF+len, p++) {
ss << *p;
}
str = ss.str();
}
Add formatting options as you wish.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Sep 11th, 2002, 02:37 AM
#5
Thread Starter
Lively Member
I sussed it!!!
I used sprintf and it solved the problem....sorry for the confusion, i guess it was me not knowing what i am doing!!! Im a hardware engineer after all, not a softy!
Thanks
Matt
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
|