educative.io

Educative

Typo in second example

I think that comment “/// ooops?” is not necessary in example:

#include <iostream>
using namespace std;

int main() {
  std::string s = "Hello World";
  std::cout << s.size() << '\n'; 
  std::string_view sv = s;
  auto sv2 = sv.substr(0, 5);
  std::cout << sv2.data() << '\n'; /// ooops?
}

because it’s valid example.

P.S. it’s my fist topic I am not sure that I have done everything correctly

Hi Oleg,
This is Samreen Fatima from Educative.

The “ooops” here alludes to the unexpected output of this cout statement. The person would expect the substring “Hello” to be printed, instead “Hello World” is printed.

Best Regards,
Samreen Fatima | Developer Advocate
Educative

Thanks for clarifications