4 years, 7 months ago.

using iostream cin>> to enter strings with mbed, how to make a 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(Linux Ctrl-D) in command line, how to make an EOF to end the stream of serial in mbed?

istream_iterator

#include "mbed.h"
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
 
using namespace std;
 
DigitalOut myled(LED1);
vector<string> sentence;
 
int main() {
  copy(istream_iterator<string>(cin),
       istream_iterator<string>(),
       back_inserter(sentence));
 
  copy(sentence.begin(), sentence.end(),
       ostream_iterator<string>(cout," "));
  cout<<endl;
}
Be the first to answer this question.