is there a way to convert numbers to strings ?
the number could be integer/float ..
www.akilla.tk
is there a way to convert numbers to strings ?
the number could be integer/float ..
www.akilla.tk
for int
char *_itoa( int value, char *string, int radix );
for float
char *_fcvt( double value, int count, int *dec, int *sign )
look um up.
ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.
The format specifiers are the same as for printf.Code:char word[20]; int number1 = 12345; float number2 = 678.9; sprintf(word, "%d %f", number1, number2); cout << word;
the output is
12345 678.900024
here's my code...
COOL PROGRAMS @ www.akilla.tkPHP Code:
#include <stdio.h>
#include <iostream.h>
main()
{
char word[20];
int number1 = 12345;
float number2 = 678.9;
sprintf(word, "%d %f", number1, number2);
cout << word;
cin.get();
}
By the way, how do you know about these functions ??for int
char *_itoa( int value, char *string, int radix );
for float
char *_fcvt( double value, int count, int *dec, int *sign )
look um up.
Is there a book that tells all these things that I can refer
to ? Is it online ?
COOL PROGRAMS @ www.akilla.tk
That's the disadvantage of using floats.Originally posted by Unregistered
the output is
12345 678.900024
Your program is good (you could try: %.1f) but the OS can't handle floats very well.
You can take a look in the Microsoft MSDN library for example: _itoaOriginally posted by Unregistered
By the way, how do you know about these functions ??
Is there a book that tells all these things that I can refer
to ? Is it online ?
>
By the way, how do you know about these functions ??
Is there a book that tells all these things that I can refer
to ?
<
butt loads of questions, and research such as reading my headers, and the MSDN as Monster posted, it defines and explains virtually every function in standard C/C++ and many other languages.
it is Microsofts single greatest accomplishment.
>Is it online ?
yeah,
http://msdn.microsoft.com
ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.
I like this one as well:
On my machine (Solaris CC compiler) I don't have that pesky formatting problem.Code:#include <sstream> using namespace std; int main() { ostringstream oss, oss2; oss << 12345; oss2 << 678.9; string s1 = oss1.str(), s2 = oss2.str(); cout << s1 << endl << s2 << endl; }
Claus Hetzer
Compiler: Borland 5.5 (on Windows)
Solaris CC (on Unix)
Known Languages: C++, MATLAB, Perl, Java
Perhaps you could write an algorithm to do it? It is not as difficult as you may think...
Code:#include <cmath> #include <complex> bool euler_flip(bool value) { return std::pow ( std::complex<float>(std::exp(1.0)), std::complex<float>(0, 1) * std::complex<float>(std::atan(1.0) *(1 << (value + 2))) ).real() < 0; }