Std::cin inside work()

Dear sir,
Why below custom block doesn’t work…?

int
console1_impl::work(
          int noutput_items,
          gr_vector_const_void_star &input_items,
          gr_vector_void_star &output_items)
{
    int *out = (int *) output_items[0];

    int x;
    std::cout << "Please key in an integer: ";
    std::cin >> x;
    std::cout << "You have given me " << x << std::endl;

    out[0] = x;
    return 1;
}

On 03/26/2014 09:17 AM, Activecat wrote:> Dear sir,

Why below custom block doesn’t work…?

Activecat,

first, don’t ask open questions like this. How do you know it’s not
working? What did you try? Is there an error message? Always provide all
of these infos when asking questions. You will get much better answers.
Make sure you’ve read
http://gnuradio.org/redmine/projects/gnuradio/wiki/ReportingErrors.

    std::cin >> x;
    std::cout << "You have given me " << x << std::endl;

    out[0] = x;
    return 1;
}

A couple of guidelines:

  • Don’t block in work()! (i.e., don’t do this)
  • This would probably be better solved by passing info into the stream
    with other means, e.g. messages (PDUs), or by writing to a pipe and
    reading from there.
  • Try adding a std::flush after the first cout.

M

Thank you very much.