Puzzle 18Moving Out

 #include <iostream>
 #include <string>
 
 int​ ​main​()
 {
  std::string hello{​"Hello, World!"​};
  std::string other(std::move(hello));
  std::cout << ​"'"​ << hello << ​"'"​;
 }

Guess the Output

images/aside-icons/important.png

Try to guess what the output is before moving to the next page.

images/hline.png

The program has unspecified behavior! But it probably outputs the following:

 ''
images/hline.png

Discussion

A moved-from object should no longer be used, as resources ...

Get C++ Brain Teasers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.