c++ 从标注输入流读取行
#include <string.h> #include <iostream> #include <vector> #include <stdio.h> #include <stdlib.h> #include <boost/algorithm/string.hpp> int main() { //std::string bns = "list://cp01-spi-fresh2.cp01.baidu.com:8004"; std::string bns = "bns://exdata-server.ps-wcb.yq01"; baidu::rpc::ChannelOptions option; option.connection_type = baidu::rpc::CONNECTION_TYPE_SINGLE; baidu::rpc::Channel channel; if(channel.Init(bns.c_str(), "rr", &option) != 0){ return -1; } ps::spider::ExdataService_Stub stub(&channel); char str[1024]; while(true){ char* l = fgets(str, sizeof(str), stdin); if(NULL == l) break; int len = strlen(str); str[len-1] = '\0'; std::string line = str; if(line.empty()) continue; std::vector<std::string> tokens; boost::split(tokens, line, boost::is_any_of("\t")); if(tokens.size() == 2){ //.........云云 } return 0; } /* vim: set ts=4 sw=4 sts=4 tw=100 */