Home > Net >  MSVS2017, Boost C error with namespaces
MSVS2017, Boost C error with namespaces

Time:04-08

Can anyone help me out. I stumbled into a roadblock.

I've modified the project properties to include the Boost header path, and Boost linker path--plus the 'not using predefined header files' options'

Some how, Visual studio can't see std_in/std_out as part of the boost::process namespace.

I've compile the same file on Linux, and it works fine. Same version of Boost 1.78.0.

namespace bp = ::boost::process;


bp::opstream chldInput;
bp::ipstream chldOutput;

bp::child c(cmd.c_str(), bp::std_out > chldInput, bp::std_in < chldOutput);

CodePudding user response:

It's not that it can't see bp::std_in and bp::std_out. It's because you've swapped the streams.

  • ipstream is an implementation of a reading pipe stream - a stream that you can use in a similar way as std::istreams, like std::cin.
  • opstream is an implementation of a write pipe stream - a stream that you can use in a similar way as std::ostreams, like std::cout.

However, bp::std_out needs to go to a bp::ipstream (which you then can read from) and bp::std_in needs its input from an bp::opstream (that you can write to).

Example:

bp::child c(cmd.c_str(), bp::std_out > chldOutput, bp::std_in < chldInput);

Since chldInput isn't connected to anything, you may want to use stdin instead:

bp::child c(cmd.c_str(), bp::std_out > chldOutput, bp::std_in < stdin);

You may also want to c.wait() for the command to finish.

Swapping the streams like you've done will likely generate an error like

program.cpp: In function ‘int main()’:
program.cpp: error: no match for ‘operator>’ (operand types are ‘const boost::process::detail::std_out_<1>’ and ‘boost::process::opstream’ {aka ‘boost::process::basic_opstream<char>’})
      |     bp::child c(cmd.c_str(), bp::std_out > chldInput, bp::std_in < chldOutput);
      |                              ~~~~~~~~~~~ ^ ~~~~~~~~~
      |                                  |         |
      |                                  |         boost::process::opstream {aka boost::process::basic_opstream<char>}
      |                                  const boost::process::detail::std_out_<1>

(and a few hundred lines more).

  • Related