Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Using C's sprinf() Function to Format Output String
// Using C's Sprintf to Format Output String. #include <iostream> #include <cstdio> #include <set> #include <utility> using namespace std; int main() { double data[] = {1.00, 1.50, 2.00, 2.25, 2.50, 3.75, 4.00}; int datasize = sizeof(data)/sizeof(double); set<double, greater<double> >gSet; char buffer[datasize]; cout << "\nIndex\tValue\n\n"; for(int i = 0; i < datasize; i++){ pair<set<double, greater<double> >::iterator, bool>pi = gSet.insert(data[i]); sprintf(buffer, "%i%s%2.2f", i+1, "\t", *pi.first); cout << buffer << "\n"; } }
run
|
edit
|
history
|
help
0
czekolada
Kolokwium_2011_z12
Equilateral triangle
Variadic Functor Example
C++
Rubix
N Qeens problem
0-1 Knapsack
k1
wealth of banks