aterialized
temporary object. All implementations directly return the prvalue instead. The
requirement is corrected by the post-C++20 proposal [ P0849R8
](https://wg21.link/P0849R8) to match the implementations.

###  [ [ edit ](/mwiki/index.php?title=cpp/ranges/data&action=edit&section=2
"Edit section: Example") ]  Example

Run this code

    
    
    #include <cstring>
    #include <iostream>
    #include <ranges>
    #include <string>
     
    int main()
    {
        [std::string](http://en.cppreference.com/w/cpp/string/basic_string) s{"Hello world!\n"};
     
        char a[20]; // storage for a C-style string
        [std::strcpy](http://en.cppreference.com/w/cpp/string/byte/strcpy)(a, std::[ranges::data](http://en.cppreference.com/w/cpp/ranges-ranges-placeholder/data)(s));
        // [data(s), data(s) + size(s)] is guaranteed to be an NTBS
     
        [std::cout](http://en.cppreference.com/w/cpp/io/cout) << a;
    }

Output:

    
    
    Hello world!

###  [ [ edit ](/mwiki/index.php?title=cpp/ranges/data&action=edit&section=3
"Edit section: See also") ]  See also

[ ranges::cdata  ](/w/cpp/ranges/cdata "cpp/ranges/cdata") (C++20)  |  obtains a pointer to the beginning of a read-only contiguous range   
(customization point object)  [ [edit]
](https://en.cppreference.com/mwiki/index.php?title=Template:cpp/ranges/dsc_cdata&action=edit)  
---|---  
[ ranges::begin  ](/w/cpp/ranges/begin "cpp/ranges/begin") (C++20)  |  returns an iterator to the beginning of a range   
(customization point object)  [ [edit]
](https://en.cppreference.com/mwiki/index.php?title=Template:cpp/ranges/dsc_begin&action=edit)  
[ data  ](/w/cpp/iterator/data "cpp/iterator/data") (C++17)  |  obtains the pointer to the underlying array   
(function template)  [ [edit]
](https://en.cppreference.com/mwiki/index.php?title=Template:cpp/iterator/dsc_data&action=edit)  
  
Retrieved from " [
https://en.cppreference.com/mwiki/index.php?title=cpp/ranges/data&oldid=160936
](https://en.cppreference.com/mwiki/index.php?title=cpp/ranges/data&oldid=160936)
"

#####  Navigation

  * [ Support us ](http://www.cppreference.com/support)
  * [ Recent changes ](/w/Special:RecentChanges "A list of recent changes in the wiki \[r\]")
  * [ FAQ ](/w/Cppreference:FAQ)
  * [ Offline version ](/w/Cppreference:Archives)

#####  Toolbox

  * [ What links here ](/w/Special:WhatLinksHere/cpp/ranges/data "A list of all wiki pages that link here \[j\]")
  * [ Related changes ](/w/Special:RecentChangesLinked/cpp/ranges/data "Recent changes in pages linked from this page \[k\]")
  * [ Upload file ](http://upload.cppreference.com/w/Special:Upload "Upload files \[u\]")
  * [ Special pages ](/w/Special:SpecialPages "A list of all special pages \[q\]")
  * [ Printable version ](/mwiki/index.php?title=cpp/ranges/data&printable=yes "Printable version of this page \[p\]")
  * [ Permanent link ](/mwiki/index.php?title=cpp/ranges/data&oldid=160936 "Permanent link to this revision of the page")
  * [ Page information ](/mwiki/index.php?title=cpp/ranges/data&action=info)

  * In other languages 

  * [ Deutsch ](http://de.cppreference.com/w/cpp/ranges/data "cpp/ranges/data")
  * [ Español ](http://es.cppreference.com/w/cpp/ranges/data "cpp/ranges/data")
  * [ 日本語 ](http://ja.cppreference.com/w/cpp/ranges/data "cpp/ranges/data")
  * [ Русский ](http://ru.cppreference.com/w/cpp/ranges/data "cpp/ranges/data")
  * [ 中文 ](http://zh.cppreference.com/w/cpp/ranges/data "cpp/ranges/data")

  * This page was last modified on 19 October 2023, at 01:43. 
  * This page has been accessed 17,802 times. 

  * [ Privacy policy ](/w/Cppreference:Privacy_policy "Cppreference:Privacy policy")
  * [ About cppreference.com ](/w/Cppreference:About "Cppreference:About")
  * [ Disclaimers ](/w/Cppreference:General_disclaimer "Cppreference:General disclaimer")

  * [ ![Powered by MediaWiki](/mwiki/skins/common/images/poweredby_mediawiki_88x31.png) ](//www.mediawiki.org/) [ ![Powered by GeSHi](//upload.cppreference