Use a file as input the same way the consule is used

Hello, is there some way I can take a txt file and have it wait for user input. This would work the same way as the console and cin. I do not want to read some premade text but rather wait for the user to type something into the file.
Thank you
1
2
3
4
5
6
// open the file
std::ofstream file( "file_name" ) ;

// write the lines entered by the user into the file one by one 
std::string str ;
while( std::getline( std::cin, line ) file << line << '\n' ;

Topic archived. No new replies allowed.