Files
boost_detail/test/iomanip_test.cpp
T
Bryce Adelstein-Lelbach 4a1c553f90 Replacing the use of <iomanip> with <boost/detail/iomanip.hpp> across Boost.
On Linux, GNU's libstdc++, which is the default stdlib for icc and clang,
cannot parse the <iomanip> header in version 4.5+ (which thankfully neither
compiler advises the use of yet), as it's original C++98-friendly
implementation has been replaced with a gnu++0x implementation.
<boost/detail/iomanip.hpp> is a portable implementation of <iomanip>, providing
boost::detail::setfill, boost::detail::setbase, boost::detail::setw,
boost::detail::setprecision, boost::detail::setiosflags and
boost::detail::resetiosflags. 



[SVN r68140]
2011-01-14 02:35:58 +00:00

60 lines
1.4 KiB
C++

/*==============================================================================
Copyright (c) 2010-2011 Bryce Lelbach
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
==============================================================================*/
#include <iostream>
#include <sstream>
#include <boost/config.hpp>
#include <boost/detail/iomanip.hpp>
#include <boost/detail/lightweight_test.hpp>
int main (void) {
using namespace boost::detail;
std::ostringstream oss(std::ostringstream::out);
//[setbase_test
oss << setbase(8) << 8;
BOOST_TEST_EQ(oss.str(), "10");
oss.str("");
oss << setbase(10) << 10;
BOOST_TEST_EQ(oss.str(), "10");
oss.str("");
oss << setbase(16) << 16;
BOOST_TEST_EQ(oss.str(), "10");
//]
//[setiosflags_test
oss.str("");
oss << setiosflags(std::ios_base::showbase | std::ios_base::hex) << 16;
BOOST_TEST_EQ(oss.str(), "0x10");
//]
//[resetiosflags_test
oss.str("");
oss << resetiosflags(std::ios_base::showbase | std::ios_base::hex) << 16;
BOOST_TEST_EQ(oss.str(), "16");
//]
//[setprecision_test
oss.str("");
oss << setprecision(4) << 3.14159;
BOOST_TEST_EQ(oss.str(), "3.142");
//]
//[setfill_and_setw_test
oss.str("");
oss << setfill('*') << setw(5) << 9;
BOOST_TEST_EQ(oss.str(), "****9");
//]
return boost::report_errors();
}