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…
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…
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".
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…
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,…
I have the following configuration in c_cpp_properties.json:
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
…
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…
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…
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 {
…
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…
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…
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…
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 =…
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…
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…