cout << "," << temp;

cout as default does not output leading 0's to pad fill a number to a set width! You have to tell cout what width to use and what fill character to use if you want leading...