본문 바로가기
C++/0x03-c++17

string_view ][ c++1z

by SpeeDr00t 2016. 9. 20.
반응형

string_view ][ c++1z


1.소스

#include <iostream>
#include <experimental/string_view>

void* operator new(std::size_t n)
{
    std::cout << "[allocating " << n << " bytes]\n";
    return malloc(n);
}

bool compare(const std::experimental::string_view& s1, const std::experimental::string_view& s2)
{
    if (s1 == s2)
        return true;
    std::cout << '\"' << s1 << "\" does not match \"" << s2 << "\"\n";
    return false;
}

int main()
{
    std::string str = "this is my input string";

    compare(str, "this is the first test string");
    compare(str, "this is the second test string");
    compare(str, "this is the third test string");

    return 0;
}


2. 컴파일

g++ -std=c++1z -Wall -Wextra -Werror string_view.cpp 



반응형

'C++ > 0x03-c++17' 카테고리의 다른 글

substr ][ c++1z  (0) 2016.09.20