C++17 からの string_view は substr の代わりに ― 2021年06月01日 12時19分02秒
そんな分けで簡単な例。
実行結果。
% cat string_view.cpp
#include <string>
#include <string_view>
#include <iostream>
int main()
{
std::string s( "Hello C++" );
char ch[] = "Hello C++";
std::string_view s1( &s[ 0 ], 6 );
std::string_view s2( ch + 6, 3 );
std::cout << s1 << std::endl;
std::cout << s2 << std::endl;
}
% c++ -std=c++17 string_view.cpp
% ./a.out
Hello
C++
最近のコメント