std::size_t readFromCsvReader(std::size_t nrows, std::size_t ncols) { BenchmarkInputBuffer buffer(nrows,ncols); { std::istream ist(&buffer); csv::Reader reader(ist, csv::Specification() .withSeparator(' ') .withSeparator(' ') .withoutHeader()); int a; int hash = 0; std::size_t counter = 0; std::size_t row_counter = 0; for(auto row : reader) { for(auto cell : row) { a = cell.as<int>(); hash+= a; counter++; } row_counter++; } return counter; } }
RC AlgorithmDataFile::ParseLine(const wstring &line) { RC rc; wistringstream ist(line); UINT32 algorithmId; wstring name, dllFileName, funcName, iconFileName; ist >> algorithmId >> name >> dllFileName >> funcName >> iconFileName; ParamNameList paramNameList; while (!ist.eof()) { wstring paramName; ist >> paramName; if (!paramName.empty()) { paramNameList.push_back(paramName); } } m_InternalAlgorithmMap[algorithmId] = InternalAlgorithm(algorithmId, name, dllFileName, funcName); return rc; }
void InputFileText::readData(std::vector<T> &buff, int ncol, long frow, long lrow) { if(!isOpened()) throw IOException("Error in InputFileText::readData() ", 0); int buff_sz = lrow - frow + 1; int buff_off = 0; fileStream.clear(); fileStream.seekg(0, std::ios::beg); buff.resize(buff_sz); for(int i = frow; i < lrow+1; i++) { std::string line; if(getline(fileStream, line)) { int first = 0; int last = 0; int colCounter = 0; while(colCounter <= ncol && colCounter <= ncols) { findField(line,first,last,last); colCounter++; } if(colCounter == ncol+1) { std::istringstream ist(std::string(line,first,last-first)); ist >> buff[buff_off++]; } } else throw IOException("InputFileText::readData()", 0);
int main(int argc, const char ** argv) { std::stringstream ist(planets_csv); csv::Reader reader(ist, csv::Specification().withHeader()); auto planets = readPlanetList(reader); Planet avg = Planet { index : 0, name : "avg", diameter : 0, mass : 0, orbital_period : 0, rotation_period : 0 }; for(auto planet : planets) { avg.diameter+= planet.diameter / planets.size(); avg.mass+= planet.mass / planets.size(); avg.orbital_period+= fabs(planet.orbital_period) / planets.size(); avg.rotation_period+= fabs(planet.rotation_period) / planets.size(); } std::cout << "avg diameter " << avg.diameter << std::endl; std::cout << "avg mass " << avg.mass << std::endl; std::cout << "avg orbital_period " << avg.orbital_period << std::endl; std::cout << "avg rotation_period " << avg.rotation_period << std::endl; return 0; }
void read_data(std::istream& in_stream, std::vector<T>& vec, string delim="\t", // delimiter of data string comment_sep="#", // Seperator between data and comments string eof="END") // End-of-file signal { string nextline=""; while( in_stream || nextline.length() > 0 ) { string line; if( nextline.length() > 0 ) { line = nextline; // we read ahead; use it now nextline = ""; } else { std::getline(in_stream, line); } // ignore comments line = line.substr( 0, line.find(comment_sep) ); // check for end-of-file signal if( eof != "" && line.find(eof != string::npos ) return; trim(line); if( line == "" ) return; typedef std::istream_iterator<T> is_iter; std::istringstream ist(line); std::copy( is_iter(ist), is_iter(), std::back_inserter(vec) ); std::getline(in_stream, nextline); } }
void iter2_ist(void* _conf, const struct operator_s* normaleq_op, unsigned int D, const struct operator_p_s** prox_ops, const struct linop_s** ops, const struct operator_p_s* xupdate_op, long size, float* image, const float* image_adj, const float* image_truth, void* obj_eval_data, float (*obj_eval)(const void*, const float*)) { assert(D == 1); #if 0 assert(NULL == ops); #else UNUSED(ops); #endif UNUSED(xupdate_op); struct iter_ist_conf* conf = _conf; float eps = md_norm(1, MD_DIMS(size), image_adj); if (checkeps(eps)) goto cleanup; assert((conf->continuation >= 0.) && (conf->continuation <= 1.)); ist(conf->maxiter, eps * conf->tol, conf->step, conf->continuation, conf->hogwild, size, (void*)normaleq_op, select_vecops(image_adj), operator_iter, operator_p_iter, (void*)prox_ops[0], image, image_adj, image_truth, obj_eval_data, obj_eval); cleanup: ; }
void iter2_ist(iter_conf* _conf, const struct operator_s* normaleq_op, unsigned int D, const struct operator_p_s* prox_ops[D], const struct linop_s* ops[D], const float* biases[D], const struct operator_p_s* xupdate_op, long size, float* image, const float* image_adj, struct iter_monitor_s* monitor) { assert(D == 1); assert(NULL != prox_ops[0]); assert(NULL == biases); #if 0 assert(NULL == ops); #else UNUSED(ops); #endif UNUSED(xupdate_op); auto conf = CAST_DOWN(iter_ist_conf, _conf); float eps = md_norm(1, MD_DIMS(size), image_adj); if (checkeps(eps)) goto cleanup; assert((conf->continuation >= 0.) && (conf->continuation <= 1.)); ist(conf->maxiter, eps * conf->tol, conf->step, conf->continuation, conf->hogwild, size, select_vecops(image_adj), OPERATOR2ITOP(normaleq_op), OPERATOR_P2ITOP(prox_ops[0]), image, image_adj, monitor); cleanup: ; }
int main(int argc,char *argv[]) { try { URI uri("http://schlumpf/dope/test.php3"); HTTPStreamBuf layer0(uri); URLEncodeStream<HTTPStreamBuf> out(layer0); #ifndef WIN32 signal(SIGPIPE,sigPipeHandler); #endif form f; f.foo="hey this is foo"; f.bar="hey this is bar"; f.i=40700; out.simple(f,NULL); layer0.sync(); char c; std::istream ist(&layer0); while (ist.get(c)) std::cout.put(c); std::cout << std::endl; return 0; }catch (const std::exception &error){ std::cerr << "Uncaught std::exception: "<<error.what()<< std::endl; }catch (const char *error){ std::cerr << error << std::endl; }catch(...){ std::cerr << "Uncaught unknown exception\n"; } return 1; }
yfs_client::inum yfs_client::n2i(std::string n) { std::istringstream ist(n); unsigned long long finum; ist >> finum; return finum; }
/* .pheno files * space separated: * FID, IID, phenotype (1 control, 2 case) */ void readPheno(const std::string& filename, std::vector<Sample>& samples, std::unordered_map<std::string,int>& sample_map) { std::ifstream ist(filename.c_str()); if (!ist) { throw std::runtime_error("Could not open pheno file " + filename + "\n"); } // Read in Sample s; while (ist >> s) { samples.push_back(s); } // Always keep samples sorted, for consistency between programs std::sort(samples.begin(), samples.end(), Sample::compareSamples); // Map of sample names to index in vector for (unsigned int sample_index = 0; sample_index < samples.size(); ++sample_index) { sample_map[samples[sample_index].iid()] = sample_index; } }
void update(void* instance) { InstancePtr inst = (InstancePtr) instance; MyInstancePtr my = inst->my; const char delimiter =','; std::string input = inst->in_string->text; size_t nr = trim_int(inst->in_entry->number,1,1000) - 1; std::istringstream ist(input); std::vector<std::string> tokens; std::string w; while (std::getline(ist, w, delimiter)) tokens.push_back(w); inst->out_len->number = tokens.size(); if (tokens.empty()) { string_charAssign(inst->out_token, ""); } else { nr %= tokens.size(); assert(0 <= nr && nr < tokens.size()); string_charAssign(inst->out_token, tokens[nr].c_str()); } }
size_t HTTPFetchHeadParser::readStatusCode(size_t pos) { size_t nextPos = headerString.find(' ', pos); if(nextPos == std::string::npos) throw HTTPFetchHeadParserException(); std::istringstream ist(headerString.substr(pos, nextPos-pos)); ist >> header.statusCode; return ++nextPos; }
void _IOWrapper::FromStringImpl(_IOWrapper::BaseRead& b, const std::string& s, std::streamsize precision) { std::istringstream ist(s); ist.precision(precision); b.read(ist); }
void fill_from_file(vector<int>& points,const string& name) { fstream ist( name ); if (!ist) error("can't open input file ", name); int p; while (ist >> p) points.push_back(p); }
void LoadFromFile(MyTree<T>* &root, string filename) { // пример входной строки - "C:\\input.txt" ifstream ist(filename); // поток для чтения из файла T val; while (ist >> val) { Add(root, val); } }
void CoreData::updateReport() { QMapIterator<QString, SignStats*> ist(statsReports); while (ist.hasNext()) { ist.next(); SignStats * stats = ist.value(); updateStats(stats); } }
int main() { try { vector<int>number; //建立向量来存储文件中的整数 cout << "Please enter input file name: "; //读取文件 string name; cin >> name; ifstream ist(name.c_str()); if (!ist)throw file_error{}; //若文件无法正常打开,抛出异常 int x; while (true) { ist >> x; number.push_back(x); if (ist.bad())throw serious_error{}; //对输入状态进行处理 if (ist.eof())break; if (ist.fail())throw input_error{}; } int sum=0; for (int i = 0; i < number.size(); i++) { sum += number[i]; } cout << "总和为:" << sum << endl; getchar(); getchar(); getchar(); } catch (file_error) //捕获异常并处理 { cout << "无法打开文件" << endl; getchar(); getchar(); getchar(); return 0; } catch (serious_error) { cout << "something is wrong" << endl; getchar(); getchar(); getchar(); return 0; } catch (input_error) { cout << "您的输入有误,无法完成求和" << endl; getchar(); getchar(); getchar(); return 0; } }
Decoder::Sentence* Decoder::parseLine(Lexicon* lex, const std::string& line){ istringstream ist(line); std::string token; Sentence* sent=new Sentence; while ( ist >> token){ sent->push_back(lex->getWord_or_add(token).wordId()); } return sent; }
void CoreData::clearStats() { QMapIterator<QString, SignStats *> ist(statsReports); while (ist.hasNext()) { ist.next(); SignStats * stats = ist.value(); delete stats; stats = 0; } statsReports.clear(); }
vector<int> read_file(const string& filename) { int num; vector<int> k; ifstream ist(filename.c_str()); if (!ist) error("Don`t read this filename:",filename); while (ist >> num) { k.push_back(num); if (ist.eof()) break; } return k; }
/* * returns a known method among HTTP_METH_* or HTTP_METH_OTHER for all unknown * ones. */ enum http_meth_t find_http_meth(const char *str, const int len) { const struct ist m = ist2(str, len); if (isteq(m, ist("GET"))) return HTTP_METH_GET; else if (isteq(m, ist("HEAD"))) return HTTP_METH_HEAD; else if (isteq(m, ist("POST"))) return HTTP_METH_POST; else if (isteq(m, ist("CONNECT"))) return HTTP_METH_CONNECT; else if (isteq(m, ist("PUT"))) return HTTP_METH_PUT; else if (isteq(m, ist("OPTIONS"))) return HTTP_METH_OPTIONS; else if (isteq(m, ist("DELETE"))) return HTTP_METH_DELETE; else if (isteq(m, ist("TRACE"))) return HTTP_METH_TRACE; else return HTTP_METH_OTHER; }
std::string FileReader::getFieldAsString(const int n) { failed = false; std::istringstream ist(line); this->skip_fields(ist, n-1); std::string rval; ist >> rval; if (ist.fail()) { failed = true; return std::string(); } else return rval; }
double FileReader::getFieldAsDouble(const int n) { failed = false; std::istringstream ist(line); this->skip_fields(ist, n-1); double rval; ist >> rval; if (ist.fail()) { failed = true; return 0.0; } else return rval; }
RC ComponentTypeDataFile::ParseLine(const wstring &line) { RC rc; wistringstream ist(line); wstring dllFileName; ist >> dllFileName; // FIXME: When release? HINSTANCE componentDllHandle = LoadLibrary(dllFileName.c_str()); if (!componentDllHandle) { Utility::PromptLastErrorMessage(); return RC::PLATFORM_LOADDLL_ERROR; } Component::RegisterInterfaceTypeFunc registerInterfaceTypeFunc = (Component::RegisterInterfaceTypeFunc)GetProcAddress( (HMODULE)componentDllHandle, Component::RegisterInterfaceTypeFuncName); if (registerInterfaceTypeFunc) { registerInterfaceTypeFunc(m_InterfaceTypeMap); } Component::RegisterComponentTypeFunc registerComponentTypeFunc = (Component::RegisterComponentTypeFunc)GetProcAddress( (HMODULE)componentDllHandle, Component::RegisterComponentTypeFuncName); if (registerComponentTypeFunc) { registerComponentTypeFunc(m_ComponentTypeMap, componentDllHandle); } Component::SetPlatformServiceFunc setPlatformServiceFunc = (Component::SetPlatformServiceFunc)GetProcAddress( (HMODULE)componentDllHandle, Component::SetPlatformServiceFuncName); if (setPlatformServiceFunc) { setPlatformServiceFunc(m_PlatformService); } return rc; }
// is the filename readable ? bool SettingLoader::isReadable(const tstringi &i_filename, int i_debugLevel) const { if (i_filename.empty()) return false; #ifdef UNICODE tifstream ist(to_string(i_filename).c_str()); #else tifstream ist(i_filename.c_str()); #endif if (ist.good()) { if (m_log && m_soLog) { Acquire a(m_soLog, 0); *m_log << _T(" loading: ") << i_filename << std::endl; } return true; } else { if (m_log && m_soLog) { Acquire a(m_soLog, i_debugLevel); *m_log << _T("not found: ") << i_filename << std::endl; } return false; } }
T getField(const int n, bool &failed) { failed = false; std::istringstream ist(line); this->skip_fields(ist, n-1); T rval; ist >> rval; if (ist.fail()) { failed = true; std::cout << "Problem reading file" << std::endl; return rval; } else return rval; };
//******************************************************************************** float FileReader::getFieldAsFloat(const int n) { m_failed = false; std::istringstream ist(m_line); this->skip_fields(ist, n-1); float rval; ist >> rval; if ( ist.fail() ) { m_failed = true; return 0.0; } else return rval; }
std::size_t readFromIstream(std::size_t nrows, std::size_t ncols) { BenchmarkInputBuffer buffer(nrows,ncols); { std::istream ist(&buffer); int a; int hash = 0; std::size_t counter = 0; while(ist >> a) { hash+=a; counter++; } return counter; } }
void Decoder::readTable(const char filename[], double prune_threshold, unsigned int prune_count){ //==================Einlesen der Phrasentabelle============================ PTree< pair <unsigned int, double> > pruningTree; //speichert für jede Übersetzung die Anzahl der eingelesenen Übersetzungen und die beste Übersetzung pair <unsigned int, double> pruningStart; //die Startkombi für den PruningTree pruningStart.first=0; pruningStart.second=(1./0.); igzstream in(filename); std::string line,token; while(getline(in,line)){ std::stringstream ist(line); double relfreq_f, relfreq_e, source_to_target, target_to_source, unigram_sprachmodell; unsigned int singlecf, singlece; vector<uint> ephrase, fphrase; //Ausgabe: relfreq_f relfreq_e # quellphrase # zielphrase # singlecf singlece # source_to_target target_to_source # unigram-sprachmodell ist >> relfreq_f >> relfreq_e >>token; // token für "#" while(ist>>token && token != "#"){ fphrase.push_back(flex->getWord_or_add(token).wordId()); } while(ist>>token && token != "#"){ ephrase.push_back(elex->getWord_or_add(token).wordId()); } ist >> singlecf >> singlece >> token >> source_to_target >> target_to_source >> token >> unigram_sprachmodell; Cost kosten=Cost(); kosten.calc(relfreq_f, relfreq_e, fphrase, ephrase, singlecf, singlece, source_to_target, target_to_source, unigram_sprachmodell); double kosten_insgesamt=kosten.cost(); pair< unsigned int, double>* pruning_infos=&pruningTree.traverse(fphrase,true,pruningStart)->c; if (kosten_insgesamt > pruning_infos->second+prune_threshold || pruning_infos->first >prune_count) continue; //pruning ergibt, wir wollen es nicht in den Ptree mitaufnehmen //if (kosten_insgesamt< pruning_infos->second) pruning_infos->second=kosten_insgesamt; _jetzt irrelevant, da ich von einer geordneten eingabe ausgehe pruning_infos->first++; schwarz->traverse(fphrase,true)->c.traverse(ephrase,true,Cost(1./0.))->c = kosten; } //cerr << " schwarz erstellt" << endl; }
// loads geometry from STL file DLL_HEADER Ng_STL_Geometry * Ng_STL_LoadGeometry (const char * filename, int binary) { int i; STLGeometry geom; STLGeometry* geo; ifstream ist(filename); if (binary) { geo = geom.LoadBinary(ist); } else { geo = geom.Load(ist); } readtrias.SetSize(0); readedges.SetSize(0); Point3d p; Vec3d normal; double p1[3]; double p2[3]; double p3[3]; double n[3]; Ng_STL_Geometry * geo2 = Ng_STL_NewGeometry(); for (i = 1; i <= geo->GetNT(); i++) { const STLTriangle& t = geo->GetTriangle(i); p = geo->GetPoint(t.PNum(1)); p1[0] = p.X(); p1[1] = p.Y(); p1[2] = p.Z(); p = geo->GetPoint(t.PNum(2)); p2[0] = p.X(); p2[1] = p.Y(); p2[2] = p.Z(); p = geo->GetPoint(t.PNum(3)); p3[0] = p.X(); p3[1] = p.Y(); p3[2] = p.Z(); normal = t.Normal(); n[0] = normal.X(); n[1] = normal.Y(); n[2] = normal.Z(); Ng_STL_AddTriangle(geo2, p1, p2, p3, n); } return geo2; }