Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
std::99 bottles of beer!
// Title: Too many cooks! (Not enough rum!) #include <boost/lexical_cast.hpp> #include <boost/version.hpp> #include <boost/format.hpp> #include <algorithm> #include <iostream> #include <vector> struct bottles_t // <---- greg's cool code! { char a : 4; char b : 4; char c : 8; }; std::string format_bottles( size_t count ) { return ( ( count == 0 ) ? "no" : boost::lexical_cast<std::string>( count ) ) + " bottle" + ( count != 1 ? "s" : "" ); } int main(int argc, char* argv[]) { std::cout << "Hello boost ver:" << BOOST_VERSION << std::endl; int i = 0; std::vector<int> bottles(99); std::generate( std::begin(bottles), std::end(bottles), [&i](){ return ++i; } ); //std::copy( std::begin(bottles), std::end(bottles), std::ostream_iterator<int>(std::cout, ", ") ); /* //altranative method std::transform( std::begin(bottles), std::end(bottles),std::ostream_iterator<std::string>(std::cout, ", "), []( int bottle ) { using boost::format; return str(format(" uck %i ") % bottle); }); */ std::cout << std::endl; std::for_each( bottles.rbegin(), bottles.rend(), []( int count ) { std::cout << format_bottles( count ) << " of beer on the wall... " << format_bottles( count ) << " of beer! Take one down, pass it around... " << format_bottles( count -1 ) << " of beer on the wall." << std::endl; } ); return 0; }
run
|
edit
|
history
|
help
0
Diamond example
Unpacking tuple
DESim Example
Union-Struct-uint32_t byte order
Template arguments may contain calls to constexpr functions.
using directives: qualified lookup rules are different from unqualified lookup rules
Math1
Array-Based Heap Example Starter Code
Program to Time Difference
Throttle Example in C++