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

substr ][ c++1z

by SpeeDr00t 2016. 9. 20.
반응형

substr ][ c++1z


1.소스

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

using namespace std;

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

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

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

    experimental::string_view sv(&str.at(str.find_first_of('m')));
    cout << "sv = " << sv << endl;

    compare(str, sv);

    return 0;
}



2.컴파일

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


결과


반응형

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

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