> Hvordan konvertere jeg en integer til en string? (I c++ med borland c++ builder 5)
Du kan bruge fx. sprintf:
#include <stdio.h>
void main( void )
{
char buffer[200], s[] = "computer", c = 'l';
int i = 35, j;
float fp = 1.7320534f;
/* Format and print various data: */
j = sprintf( buffer, "\tString: %s\n", s );
j += sprintf( buffer + j, "\tCharacter: %c\n", c );
j += sprintf( buffer + j, "\tInteger: %d\n", i );
j += sprintf( buffer + j, "\tReal: %f\n", fp );
printf( "Output:\n%s\ncharacter count = %d\n", buffer, j );
}
Output
Output:
String: computer
Character: l
Integer: 35
Real: 1.732053
character count = 71
|