run program until ctrl-d c++

C++
std::string line; 
while (std::getline(std::cin, line))
{
    std::cout << line << std::endl;
}
Source

Also in C++: