Skip to main content

fixstr::basic_fixed_string::c_str

1#
[[nodiscard]] constexpr const_pointer c_str() const noexcept;

Returns a pointer to a null-terminated character array with data equivalent to those stored in the string.

Parameters#

(none)

Return value#

Pointer to the underlying character storage. c_str() + i == std::addressof(operator[](i)) for every i in [0, size()].

Complexity#

Constant.

Example#

#include <fixed_string.hpp>#include <cstring>#include <iostream>
int main(){    constexpr const fixstr::fixed_string hello_world = "Hello, world!";    const char* const hw_data = hello_world.c_str();        std::cout << "Terminating character: ";    if (const char terminating_character = *(hw_data + hello_world.size()); terminating_character == '\0') {        std::cout << R"(\0)";    } else {        std::cout << terminating_character;    }    std::cout << std::endl;        constexpr const fixstr::fixed_string answer = "42";    std::cout << "The answer to The Ultimate Question of Life, the Universe, and Everything: "              << std::atoi(answer.c_str()) << '\n';}
Output:
Terminating character: \0The answer to The Ultimate Question of Life, the Universe, and Everything: 42