Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
8 years, 8 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?
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; }
1 Answer
8 years, 8 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) { break; } }