Przejdź do głównej zawartości

std::string_view remove_prefix() method

// Const version only
constexpr void remove_prefix( size_type n );

Moves the start of the view forward by n characters.

Undefined Behavior

The behavior is undefined

if n > size().

Parameters

  • n - number of characters to remove from the end of the view

Return value

(none)

Complexity

Constant - O(1).

Example

Main.cpp
#include <iostream>
#include <algorithm>
#include <string_view>
int main()
{
std::string str = " trim me";
std::string_view v = str;
v.remove_prefix(std::min(v.find_first_not_of(" "), v.size()));
std::cout << "String: '" << str << "'\n"
<< "View : '" << v << "'\n";
}
Possible output
String: '   trim me'
View : 'trim me'
This article originates from this CppReference page. It was likely altered for improvements or editors' preference. Click "Edit this page" to see all changes made to this document.
Hover to see the original license.

std::string_view remove_prefix() method

// Const version only
constexpr void remove_prefix( size_type n );

Moves the start of the view forward by n characters.

Undefined Behavior

The behavior is undefined

if n > size().

Parameters

  • n - number of characters to remove from the end of the view

Return value

(none)

Complexity

Constant - O(1).

Example

Main.cpp
#include <iostream>
#include <algorithm>
#include <string_view>
int main()
{
std::string str = " trim me";
std::string_view v = str;
v.remove_prefix(std::min(v.find_first_not_of(" "), v.size()));
std::cout << "String: '" << str << "'\n"
<< "View : '" << v << "'\n";
}
Possible output
String: '   trim me'
View : 'trim me'
This article originates from this CppReference page. It was likely altered for improvements or editors' preference. Click "Edit this page" to see all changes made to this document.
Hover to see the original license.