Questions tagged [string-view]

A string_view is a C++ class template that is a non-owning reference to a string.

Reference: http://en.cppreference.com/w/cpp/experimental/basic_string_view

215 questions
0
votes
0 answers

How to extract std::string from simdjson::dom::object iterator in c++?

I am trying to parse a JSON I retrieve from an API and extract string values. I have no problem to retrieve the JSON, parse it and to print out values to the standard output using string_view. However, I cannot manage to take the string_view and…
Siedler
  • 77
  • 1
  • 12
0
votes
1 answer

string_view Vs const char* performance

Is a std::string_view parameter better than a const char* one in the code below? void func( const std::string_view str ) { std::istringstream iss( str.data( ) ); // str is passed to the ctor of istringstream std::size_t pos { }; int…
digito_evo
  • 3,216
  • 2
  • 14
  • 42
0
votes
2 answers

How to get original string by string_view in c++?

For example, std::string_view strv{ "Hello" }; strv.remove_prefix(1); The original string should be "Hello". I tried using strv.data() and std::string str(strv.begin(), strv.end()); I can only get "ello" instead of "Hello".
T.Chang
  • 31
  • 3
0
votes
0 answers

What type of declaration is this ' auto check = [&](string_view s) { } ' in c++?

How check behaves as a function in this Code? int countV(string_view word) { /* Lines of codes */ auto check = [&](string_view s) { }; for (int i = 0; i < n; ++i) for (int l = 5; i + l <= n; ++l) if…
SiIconic
  • 41
  • 3
0
votes
1 answer

container of string_view's - are they always null-terminated?

Let us give any data structure containing objects of std::string_view: std::vector v{ "abc", "def" }; std::deque d{ "abc", "def" }; std::set s{ "abc", "def" }; Is it guaranteed by cpp standard,…
Michal
  • 35
  • 3
0
votes
1 answer

Please update includepath error at #include

I have the following configuration in c_cpp_properties.json: { "configurations": [ { "name": "Win32", "includePath": [ "${workspaceFolder}/**" ], "defines": [ …
hyemin ju
  • 39
  • 6
0
votes
2 answers

Does C++ 17 STL std::string_view fulfill RAII design philosiphy?

In RAII(Resource Acquisition Is Initialization), an object obtain piece of resource is the procedure of initialization itself, and resource will be held as life cycle of object, but resource in string_view only includes char * and size, which means…
benedict97
  • 25
  • 4
0
votes
0 answers

Automatic conversion from std::string to std::string_view

I have created the following NullTerminatedStringView class: Why can't my NullTerminatedStringView be created from std::string without writing explicit constructor for it? As I understand, it should be able to do it automatically. #include…
cubiii
  • 359
  • 3
  • 11
0
votes
1 answer

Is it possible to construct a modifiable view of portion in a string?

I have a match table with start and end indices of portions, in array (in a callback) - I wrap that array into vector of strings - now recently I did have the need to modify the original portions of the string. struct regexcontext { …
AnArrayOfFunctions
  • 3,452
  • 2
  • 29
  • 66
0
votes
0 answers

Using `std::string_view` arguments and converting them to `std::string` later?

During code review I repeatedly found the following pattern in some other persons code: void writeFile(std::string_view path) { auto of = std::ofstream(std::string{path}); ... } As far as I understand, using string_view in the functions…
Simon Fromme
  • 3,104
  • 18
  • 30
0
votes
1 answer

Avoiding the func(char *) api on embedded

Note: I heavily changed my question to be more specific, but I will keep the old question at end of the post, in case it is useful to anyone. New Question I am developing an embedded application which uses the following types to represent strings…
Spyros Mourelatos
  • 484
  • 1
  • 8
  • 19
0
votes
0 answers

Bug in pushing an object to a shared_ptr queue

In this code I created 2 functions in addition to the main function. One pushes an object to the queue, and the other one gets the user input and adds it to the queue as a shared pointer. When trying to print the user input which we…
Sharon
  • 21
  • 2
0
votes
0 answers

constexpr, string_view and find

I have just written this code: bool is_name_char(char c) { using namespace std::string_view_literals; constexpr const auto not_name = "[]<>/("sv; constexpr const auto b = std::begin(not_name); constexpr const auto e =…
utnapistim
  • 26,809
  • 3
  • 46
  • 82
0
votes
1 answer

Toggle pass by reference parameter based on template type C++

I am implementing a "starts_with" function to check if a string starts with some prefix. I want the function to be able to compare std::string and std::string_view interchangeably. The issue I'm running into is when a std::string is passed as an…
Rikus Honey
  • 534
  • 1
  • 3
  • 17
0
votes
1 answer

namespace "std" has no member "string_view"

I change my settings in Visual Studio C++ language standard to Preview - Features from the Latest C++ Working Draft (std:c++latest), but it still not letting me use std::string_view and shows me this message namespace "std" has no member…
user12623797