• Class / Function / Type

      std::
    • Header file

      <>
    • Other / All

    最終更新日時(UTC):
    が更新

    履歴 編集

    function
    <charconv>

    std::to_chars_result::operator bool

    constexpr explicit operator bool() const noexcept;
    

    概要

    変換が成功したかを判定する。

    戻り値

    return ec == errc{};
    

    #include <iostream>
    #include <charconv>
    #include <string_view>
    
    int main()
    {
      char out[8]{};
      int value = 123;
    
      if (auto result = std::to_chars(std::begin(out), std::end(out), value)) {
        std::cout << std::string_view(out, result.ptr - out) << std::endl;
      }
      else {
        std::cout << "conversion failed" << std::endl;
      }
    }
    

    出力

    123
    

    バージョン

    言語

    • C++26

    処理系

    参照