Legality of COW std::string implementation in C++11

It’s not allowed, because as per the standard 21.4.1 p6, invalidation of iterators/references is only allowed for — as an argument to any standard library function taking a reference to non-const basic_string as an argument. — Calling non-const member functions, except operator[], at, front, back, begin, rbegin, end, and rend. For a COW string, calling … Read more

std::string formatting like sprintf

Modern C++ makes this super simple. C++20 C++20 introduces std::format, which allows you to do exactly that. It uses replacement fields similar to those in python: #include <iostream> #include <format> int main() { std::cout << std::format(“Hello {}!\n”, “world”); } Code from cppreference.com, CC BY-SA and GFDL Check out the compiler support page to see if it’s … Read more

Converting std::string from const_iterator to char*?

You should do int error=regexec(&regex,cppstring.c_str(),nmatch,pmatch,eflags); The second argument of regexec() and the return value of std::string::c_str() are both (const char *), so that’s probably not the cause of your issue. You should post the compiler error message and the part of the code that you suspect to be causing the problem.