当前位置: 首页>>代码示例>>C++>>正文


C++ istringstream类代码示例

本文整理汇总了C++中istringstream的典型用法代码示例。如果您正苦于以下问题:C++ istringstream类的具体用法?C++ istringstream怎么用?C++ istringstream使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了istringstream类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: while

vector<string> HashTables::findMajorityWords_general(istringstream &sin, int k) {
    unordered_map<string, int> table;
    string s;
    int n=0;
    while (sin >> s) {
        table[s]++;
        n++;
        if (table.size()>=k+1) {
            for (auto it=table.begin(); it != table.end(); it++){
                if (--it->second==0) { // because it must be a item which is just added
                    table.erase(it++);
                }
            }
        }
    }

    for (auto &t:table)
        t.second=0;

    sin.clear();
    sin.seekg(0, ios::beg);
    while (sin>>s) {
        auto it = table.find(s);
        if (it != table.end())
            it->second++;
    }

    vector<string> ret;
    for (auto &t: table) {
        if (t.second>=static_cast<double>(n)/k)
            ret.emplace_back(t.first);
    }
    return ret;
}
开发者ID:zhihongzeng2002,项目名称:cppcoding,代码行数:34,代码来源:hashtables.cpp

示例2: parseF

inline void ObjIO::parseF(
    istringstream & line
,   ObjObject & object)
{
    ObjGroup & group = object.groups.empty() ? object : *object.groups.back();

    const e_FaceFormat format(parseFaceFormat(line));

    group.foffs.push_back(static_cast<GLuint>(group.vis.size()));

    GLuint i;

    while(line >> i)
    {
        group.vis.push_back(--i);

        switch(format)
        {
        case FF_V:  // v0 v1 ...

            break;

        case FF_VT: // v0/vt0 v1/vt1 ...

            line.ignore(1); // ignore slash
            line >> i;
            group.vtis.push_back(--i);

            break;
             
        case FF_VN: // v0//vn0 v1//vn1 ...

            line.ignore(2); // ignore slashes
            line >> i;
            group.vnis.push_back(--i);

            break;

        case FF_VTN: // v0/vt0/vn0 v1/vt1/vn1 ...

            line.ignore(1); // ignore slash
            line >> i;
            group.vtis.push_back(--i);

            line.ignore(1); // ignore slash
            line >> i;
            group.vnis.push_back(--i);

        default:
            break;
        }
    }
}
开发者ID:Tymolc,项目名称:CG-I-2015,代码行数:53,代码来源:objio.cpp

示例3: readConfig

void readConfig( istringstream& iss,
                 int& n_in,
                 int& n_out,
                 int& n_vocab,
                 int& n_project,
                 int& n_order,
                 float& momentum,
                 float& weight_decay,
                 float& alpha,
                 float& lnZ, 
                 string& norm_type, 
                 float& norm_param ) {
    n_in = 0;
    n_out = 0;
    n_vocab = 0;
    n_project = 0;
    n_order = 0;
    momentum = 0.0f;
    weight_decay = 0.0f;
    alpha = 0.0f;
    lnZ = 0.0f;
    norm_type = "none";
    norm_param = 10.0f;

    string token;
    while ( !iss.eof() ) {
        iss >> token;
        if ( token == "vocabulary" ) {
            iss >> n_vocab;
        }
        else if ( token == "projection" ) {
开发者ID:xmb-cipher,项目名称:iNCML-DNNLM,代码行数:31,代码来源:network.cpp

示例4: writeSymbols

result_t ValueListDataField::writeSymbols(istringstream& input,
		const unsigned char offset,
		SymbolString& output, const bool isMaster, unsigned char* usedLength)
{
	NumberDataType* numType = (NumberDataType*)m_dataType;
	if (isIgnored())
		return numType->writeRawValue(numType->getReplacement(), offset, m_length, output, usedLength); // replacement value

	const char* str = input.str().c_str();

	for (map<unsigned int, string>::iterator it = m_values.begin(); it != m_values.end(); it++)
		if (it->second.compare(str) == 0)
			return numType->writeRawValue(it->first, offset, m_length, output, usedLength);

	if (strcasecmp(str, NULL_VALUE) == 0)
		return numType->writeRawValue(numType->getReplacement(), offset, m_length, output, usedLength); // replacement value

	char* strEnd = NULL; // fall back to raw value in input
	unsigned int value;
	value = (unsigned int)strtoul(str, &strEnd, 10);
	if (strEnd == NULL || strEnd == str || (*strEnd != 0 && *strEnd != '.'))
		return RESULT_ERR_INVALID_NUM; // invalid value
	if (m_values.find(value) != m_values.end())
		return numType->writeRawValue(value, offset, m_length, output, usedLength);

	return RESULT_ERR_NOTFOUND; // value assignment not found
}
开发者ID:john30,项目名称:ebusd,代码行数:27,代码来源:data.cpp

示例5: time

void AgendaUI::createMeeting(void) {
    cout  << endl << "****************" << endl << "CreateMeeting"  << endl << "***************" << endl;
    os << "[create meeting] [title] [participator] [start time(yyyy-mm-dd/hh:mm)] [end time(yyy-mm-dd/hh:mm)]" << endl;
    os << "[create meeting] ";
    res = os.str();
    strcpy(buffer, res.c_str());
    os.str("");
    __send();
    __read();
    string title, participator, startDate, endDate;
    istringstream ss(is.str());
    ss >> title >> participator >> startDate >> endDate;

    cout << "!!!!!!!!" <<  title << participator << startDate << endDate << endl;
    if (agendaService_.createMeeting(userName_, title, participator, startDate, endDate)) {
        os << "[create meeting] succeed!" << endl;
        os << endl;
        os << "[email protected]" << userName_ << " : # ";
        res = os.str();
        strcpy(buffer, res.c_str());
        os.str("");
        __send();
        input();
    } else {
        os << "[error] create meeting fail!" << endl;
        os << endl;
        os << "[email protected]" << userName_ << " : # ";
        res = os.str();
        strcpy(buffer, res.c_str());
        os.str("");
        __send();
        input();
    }
}
开发者ID:chenzl25,项目名称:Agenda_socket,代码行数:34,代码来源:UDPUI.cpp

示例6: createFromXml

void Bank::createFromXml( istringstream& is, Program& program )
{
    Document doc;
    try
    {
	    doc.Parse( is.str(), true );
        Node* root = &doc;

        Node* programNode = doc.FirstChild( "Program", false );
        if( programNode != NULL ) {
            root = programNode;
        }

	    Iterator< Element > it( "Module" );
	    for( it = it.begin( root ); it != it.end(); it++ )
	    {
		    ModuleData* data = new ModuleData();
		    Element* moduleElement = it.Get();
		    readModule( moduleElement, data );

		    program.addModule( data );
	    }
    }
    catch( const exception& e ) {
        TRACE( e.what() );
    }
}
开发者ID:dreieier,项目名称:Nexus,代码行数:27,代码来源:Bank.cpp

示例7: parseQuotes

static void parseQuotes(istringstream& result, forward_list<pair<string,quote_>>& quotes)
{
  string row;
  string date;
  float price[4];
  result.ignore(256, '\n');

  while(result.peek() != EOF)
  {
    getline(result, date, ',');
    result>> row;
    result.ignore();
    sscanf(row.c_str(), "%f,%f,%f,%f", &price[0], &price[1], &price[2], &price[3]);

    quotes.push_front(pair<string,quote_>(date, {price[0], price[1], price[2], price[3]}));
  }
}
开发者ID:Wade-Shepardson,项目名称:Stex,代码行数:17,代码来源:retriever.cpp

示例8: getPeaks

void TandemNativeParser::getPeaks(
  istringstream& tokenizer, ///< string version of values
  float* array,            ///< store values here
  int maxSize)              ///< array size
{
    // store values
    int curIdx = 0;
    while( !tokenizer.eof() ){
        assert(curIdx < maxSize);
        tokenizer >> array[curIdx];
        curIdx++;
    }
}
开发者ID:lgatto,项目名称:proteowizard,代码行数:13,代码来源:TandemNativeParser.cpp

示例9: get

string get(istringstream & in)
{
    while(true)
    {
        while(in.get()=='\"')
        {
            string result;
            char buf;
            while(true)
            {

                buf=in.get();
                if(buf=='\"')
                {
                    in.get();
                    return result;
                }
                result+=buf;
            }
        }
    }
}
开发者ID:gespiton,项目名称:euler,代码行数:22,代码来源:Names+scores.cpp

示例10: strcpy

void AgendaUI::userLogIn(void) {
    cout  << endl << "****************" << endl << "login"  << endl << "***************" << endl;
    list<User> l = agendaService_.listAllUsers();
    if (l.empty()) {
        os << "[error] No User" << endl;
        res = os.str();
        strcpy(buffer, res.c_str());
        os.str("");
        __send();
        start_input();
        return;
    }
    os << endl;
    os << "[log in] [user name] [password]" << endl;
    os << "[log in] ";
    res = os.str();
    strcpy(buffer, res.c_str());
    os.str("");
    __send();
    __read();
    istringstream ss(is.str());
    ss >> userName_ >> userPassword_;

    // is >> userName_ >> userPassword_;
    cout << is.str() << endl;
    cout << "!!!!!!!!!" << userName_ << "   " << userPassword_ << endl;
    if (agendaService_.userLogIn(userName_, userPassword_)) {
        os << "[log in] succeed!" << endl;
        os << endl;
        help();
    } else {
        os << "[error] log in fail!" << endl;
        res = os.str();
        strcpy(buffer, res.c_str());
        os.str("");
        userLogIn();
    }
}
开发者ID:chenzl25,项目名称:Agenda_socket,代码行数:38,代码来源:UDPUI.cpp

示例11: ReadFace

bool OBJFile::ReadFace(istringstream& line){
    Face face;
    string vertex;

    while(!line.eof()){
        line >> vertex;
            vector<string> index;
            Split(vertex, index, "/");
            size_t current = strtoul(index[0].c_str(), NULL, 10)-1;
            face.Vertex.push_back(current);
    }
    m_faces.push_back(face);
    return true;

}
开发者ID:naonedier,项目名称:openDlpSlicer,代码行数:15,代码来源:OBJFile.cpp

示例12: getSequenceName

//********************************************************************************************************************
//this function will jump over commented out sequences, but if the last sequence in a file is commented out it makes a blank seq
Sequence::Sequence(istringstream& fastaString){
	try {
		m = MothurOut::getInstance();
	
		initialize();
        name = getSequenceName(fastaString);
		
		if (!m->control_pressed) { 
			string sequence;
		
			//read comments
			while ((name[0] == '#') && fastaString) { 
				while (!fastaString.eof())	{	char c = fastaString.get(); if (c == 10 || c == 13){	break;	}	} // get rest of line if there's any crap there
				sequence = getCommentString(fastaString);
				
				if (fastaString) {  
					fastaString >> name;  
					name = name.substr(1);	
				}else { 
					name = "";
					break;
				}
			}
			
			//while (!fastaString.eof())	{	char c = fastaString.get();  if (c == 10 || c == 13){ break;	}	} // get rest of line if there's any crap there
            comment = getCommentString(fastaString);
			
			int numAmbig = 0;
			sequence = getSequenceString(fastaString, numAmbig);
			
			setAligned(sequence);	
			//setUnaligned removes any gap characters for us						
			setUnaligned(sequence);	
			
			if ((numAmbig / (float) numBases) > 0.25) { m->mothurOut("[WARNING]: We found more than 25% of the bases in sequence " + name + " to be ambiguous. Mothur is not setup to process protein sequences."); m->mothurOutEndLine(); }
		}
开发者ID:jklynch,项目名称:mothur,代码行数:38,代码来源:sequence.cpp

示例13: loadBodyFromModelLoader

int loadBodyFromModelLoader(::World* world, const char* name, const char *URL, istringstream &strm)
{
    vector<string> argvec;
    while (!strm.eof()){
        string arg;
        strm >> arg;
        argvec.push_back(arg);
    }
    int argc = argvec.size();
    char **argv = new char *[argc];
    for (int i=0; i<argc; i++){
        argv[i] = (char *)argvec[i].c_str();
    }

	int ret = loadBodyFromModelLoader(world, name, URL, argc, argv);

    delete [] argv;

    return ret;
}
开发者ID:YoheiKakiuchi,项目名称:openhrp3-1,代码行数:20,代码来源:ModelLoaderUtil.cpp

示例14: deserialize

 NestedInteger deserialize(istringstream &in) {
 	int number;
     if(in>>number)	return NestedInteger(number); //如果开头是数字,那么一定是单个数的
     in.clear();
     in.get();
     NestedInteger list;
     while(in.peek() != ']')
     {
     	list.add(deserialize(in));
     	if(in.peek()==',')
     		in.get();
     }
     in.get();
     return list;
 }
开发者ID:whguo,项目名称:LeetCode,代码行数:15,代码来源:385.Mini+Parser.cpp

示例15: s

inline const ObjIO::e_FaceFormat ObjIO::parseFaceFormat(const istringstream & line)
{
    string s(line.str());
    trim(s);

    size_t l(s.find(" "));
    if(string::npos == l)
        l = s.length();

    const size_t f0(s.find("/", 0));

    if(string::npos == f0)
        return FF_V;

    const size_t f1(s.find("/", f0 + 1));

    if(string::npos == f1 || f1 > l)
        return FF_VT;

    if(string::npos == s.find("//", 0))
        return FF_VTN;
    else
        return FF_VN;
}
开发者ID:Tymolc,项目名称:CG-I-2015,代码行数:24,代码来源:objio.cpp


注:本文中的istringstream类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。