Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

PrevUpHomeNext

Supported String Types

Wide String
Custom String Types

boost::cnv::wstream wcnv;

BOOST_TEST(convert<int>(L"11", wcnv(std::hex)).value_or(0) == 17); // 11(16) = 17(10)
BOOST_TEST(convert<int>(L"11", wcnv(std::oct)).value_or(0) ==  9); // 11(8)  = 9(10)
BOOST_TEST(convert<int>(L"11", wcnv(std::dec)).value_or(0) == 11);

BOOST_TEST(convert<wstring>(254, wcnv(arg::base = cnv::base::dec)).value_or(L"bad") == L"254");
BOOST_TEST(convert<wstring>(254, wcnv(arg::base = cnv::base::hex)).value_or(L"bad") ==  L"fe");
BOOST_TEST(convert<wstring>(254, wcnv(arg::base = cnv::base::oct)).value_or(L"bad") == L"376");

    boost::cnv::wstream wcnv;

    wcnv(std::noskipws); // Do not ignore leading whitespaces

    BOOST_TEST( convert<int>(   L"123", wcnv).value_or(0) == 123);
    BOOST_TEST(!convert<int>( L"  123", wcnv));
    BOOST_TEST(!convert<int>(L"  123 ", wcnv));

    wcnv(std::skipws);        // Ignore leading whitespaces
//  wcnv(arg::skipws = true); // Ignore leading whitespaces. Alternative interface

    BOOST_TEST( convert<int>( L"  123", wcnv).value_or(0) == 123);
    BOOST_TEST(!convert<int>(L"  123 ", wcnv));


PrevUpHomeNext