5 years, 9 months ago.

using istream_iterator bind to cin in STL, how to make the serial stream end?

when I send string to mbed board by pc COM port, the mbed serial stream can't terminate, in windows VC++ can make stream end by Ctrl-Z in command line, how to make an end of stream to serial in mbed?


#include "mbed.h"
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

DigitalOut myled(LED1);
vector<string> sentence;

int main() {

  copy(sentence.begin(), sentence.end(),
       ostream_iterator<string>(cout," "));

1 Answer

5 years, 9 months ago.

I think your best bet is to use some escape sequence or escape character... It might be that VC++ has mapped CTRL+Z to one of those. I'm using something like:

        std::cout << "\nPlease, enter some values (or quit to exit): ";
        std::istream_iterator<string> iit (std::cin);
        std::istream_iterator<string> eos;
        while (iit != eos) {
            std::cout << *(iit++);
            if ((*iit).compare("quit") == 0) {

what is "eos" ? how to implement in mbed?

posted by jerry liu 23 Jun 2017