Printing With printf()
This is a third party API which may cause problems with std::string_view. We'll learn how to use them together correctly.
We'll cover the following...
For example:
Press + to interact
#include <iostream>using namespace std;int main() {std::string s = "Hello World";std::string_view sv = s;std::string_view sv2 = sv.substr(0, 5);printf("My String %s", sv2.data()); // oops?}
Instead you should use:
printf("%.*s\n", static_cast<int>(sv2.size
...