Search⌘ K
AI Features

Discussion: Moving Out

Explore the behavior of moved-from objects in C++ and understand the guarantees provided by the standard library, especially for std::string. Learn how move constructors work and discover best practices to ensure objects remain in a valid and safe state after being moved.

Run the code

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

Understanding the output

...