Monday, October 23, 2017

C++17: std::string_view

C++17 added the class template string_view, which is a kind of lightweight constant string. Here is an example:

#include <iostream>
#include <string>
#include <string_view>

int main()
  std::string_view myStringView("A rat in the house.");
  std::string myString;

  myString = myStringView;
  std::cout << myString     << " ";
  std::cout << myStringView << " ";

  std::cout << std::endl;
  return 0;
// Output: A rat in the house. A rat in the house.

No comments:

Post a Comment