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
Baaad1
1163. Last Substring in Lexicographical Order
no copy elision
add all
C++ lesson
TraceMarrix
Kth smallest element
Bank System
SOS DP
shared_ptr deleter