//功能:文件转换成string类的vector容器,文件中每一行字符串对应容器中的一个元素 //参数: // fileName: string类型,文件名 // sVec;string_vector& 类型,文件转换得到的容器 //返回值:int类型,0-文件转换正常,非0值表示转换异常 int CXxwCppPub::FileToVector(string fileName, string_vector& sVec) { //1 先讲文件转换成文件流 ifstream inFile(fileName.c_str()); if (!inFile) { return 1; } //2 将文件内容读入到string类的vector容器中,每一行对应容器中的一个元素 string s; while(getline(inFile, s)) { sVec.push_back(s); } inFile.close();//关闭文件 if (inFile.eof()) { return 0;//文件结束 } else if (inFile.bad()) { return 2;//发生系统故障 } else if (inFile.fail()) { return 3;//读入数据失败 } return 0; }
void safe_push_back(string_vector& v, std::string s, std::string note) { if(s.empty()) return; if(!note.empty()) { s += "(" + note + ")"; } v.push_back(s); }
inline void read_file( const boost::filesystem::path& path, string_vector& lines ) { std::string line; std::ifstream istr(path.string()); while (std::getline(istr, line)) lines.push_back(line); }
client::int_type client::recv_multi_bulk_reply_(string_vector & out) { int_type length = recv_bulk_reply_(prefix_multi_bulk_reply); if (length == -1) throw key_error("no such key"); for (int_type i = 0; i < length; ++i) out.push_back(recv_bulk_reply_()); return length; }
void XKeyboard::BuildLayout(string_vector& vec) { XkbRF_VarDefsRec vdr; int i = 0; char str[20] = {0}; const char s[2] = ","; char *token; char* tmp = NULL; strcpy(str, ( !_display ? NO_KEYBOARD : (XkbRF_GetNamesProp(_display, &tmp, &vdr) && vdr.layout) ? vdr.layout : DFLT_XKB_LAYOUT)); /* get the first token */ token = strtok(str, s); /* walk through other tokens */ while( token != NULL ) { vec.push_back(token); token = strtok(NULL, s); } }