std::getline

std::getline時會等待斷行符,但需要注意的是
在使用pipe redirect時,會有flush的問題

  boost::process::ipstream child_stdout;
  boost::process::opstream child_stdin;    
  boost::process::child child_process;
  child_process = boost::process::child(exe_path,
      boost::process::std_out > child_stdout,
      boost::process::std_err > child_stdout,
      boost::process::std_in < child_stdin); 
   //...
   child_stdin << "QUIT" << std::endl; //OK
   child_stdin << "QUIT\n"; //NOT OK
   child_stdin << "QUIT\n" << std::flush; //OK

std::endl本身隱含了flush,因此送出斷行符較佳的方式還是使用std::endl

This entry was posted in Tips. Bookmark the permalink.

Leave a Reply