*** IGNORE FROM HERE ***
Well, a sprintf is like a printf to string.
So if you put a sprintf(buffer, "Hello") it will copy Hello to buffer.
But you can also add numbers!!
You can do it like:
sprintf(buffer, "The number is: %d", Number)
Yes, %d (also %i) represent a int.
You can also do it with other strings with %s.
*** FINISH IGNORING ***
I tought you didn't know about sprintf. My bad, sorry, I mistook the situation.
Anyways for security reasons you should use snprintf, but as far as you do it "for yourself" it should give no big harm.
Anyways, a Constructor is a Piece of Code in a Class that gets executed when you declare one. Want a example? Here:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
class Example {
public:
Example() // Constructor
{
printf("Hello, I'm Example!\n");
}
~Example() // Destructor, will be called when you get out of the function
{
printf("Oh, GoodBye, I was the Example... :(");
getchar();
}
};
int main()
{
Example ex; // This will also print "Hello, I'm Example!", because it's in the constructor!
return 0; // The destructor will now be called because you're leaving the main function, and will print "Oh, GoodBye, I was the Example... :(".
// Also, in the destructor i've put a getchar. This will allow the console to stay up more time (Until you press a key)
}
|