992Returning output of print_r in PHP

Use it to capture output and print it in one go. For example when debugging server function with an ajax call.

$message = "hello!\n";

$a = array(
  'one' => 1,
  'two' => 2

$message .= print_r($a, true);



            [one] => 1
            [two] => 2

640printf()ing string in C++

Silly, little C++ Beginner’s mistake. How do you print strings in C++?
string test = "tssst";
Of course not, that’s C++!!! That’s how you do it:
And if you want to stop the compiler throwing warnings:
printf("%s", test.c_str());
So close, yet so far out.

452Padding with Zeros (or other characters)

int x = 11;

[NSString stringWithFormat:@"%03i", x];
// @"011"

[NSString stringWithFormat:@"%+5i", x];
// @"+++11"

[NSString stringWithFormat:@"%+05i", x];
// @"+0011"
And not really like that. 381. I’ll still have to learn a lot of C.

305Converting float to string %4.2f

printf ("floats: %4.2f %+.0e %E \n", 3.1416, 3.1416, 3.1416); floats: 3.14 +3e+000 3.141600E+000