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


C++ istringstream::clear方法代码示例

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


在下文中一共展示了istringstream::clear方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: getline

const float& CPUPercentage::get_percentage()
{
  m_stat_file.open("/proc/stat");
  getline(m_stat_file, m_stat_line);
  m_stat_file.close();

  // skip "cpu"
  m_line_start_pos = m_stat_line.find_first_not_of(" ", 3);
  m_line_end_pos = m_stat_line.find_first_of(' ', m_line_start_pos);
  m_line_end_pos = m_stat_line.find_first_of(' ', m_line_end_pos + 1);
  m_line_end_pos = m_stat_line.find_first_of(' ', m_line_end_pos + 1);
  m_line_end_pos = m_stat_line.find_first_of(' ', m_line_end_pos + 1);
  m_iss.str(m_stat_line.substr(m_line_start_pos, m_line_end_pos - m_line_start_pos));
  m_iss >> m_next_user >> m_next_nice >> m_next_system >> m_next_idle;
  m_iss.clear();

  m_diff_user   = m_next_user - m_current_user;
  m_diff_system = m_next_system - m_current_system;
  m_diff_nice   = m_next_nice - m_current_nice;
  m_diff_idle   = m_next_idle - m_current_idle;
  m_percentage = static_cast<float>(m_diff_user + m_diff_system + m_diff_nice)/static_cast<float>(m_diff_user + m_diff_system + m_diff_nice + m_diff_idle)*100.0;

  m_current_user = m_next_user;
  m_current_system = m_next_system;
  m_current_nice = m_next_nice;
  m_current_idle = m_next_idle;

  return m_percentage;
}
开发者ID:thewtex,项目名称:screen-cpu-mem,代码行数:29,代码来源:screen-cpu-usage.cpp

示例3: next_cluster

bool FirecrestInput::next_cluster( int *plane, int *ptile, int *px, int* py ) 
{
    string line ;
    if( !getline( intensities_, line ) ) return false ;
    cur_line_.str( line ) ;
    cur_line_.clear() ;
    cycle_ = 0 ;
    return cur_line_ >> *plane >> *ptile >> *px >> *py ; 
}
开发者ID:grenaud,项目名称:freeIbis,代码行数:9,代码来源:firecrest_input.cpp

示例4: 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

示例5: main

int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
freopen("out","w",stdout);
#endif
scanf("%d\n",&cas);
tt=0;
while(cas--){
    printf("Case #%d: ",++tt);
    bases.clear();
    getline(cin,strtmp);
    inss.clear();
    inss.str(strtmp);
    while(inss>>a){
        bases.push_back(a);
    }
    j=2;
    while(!test(j)){
        j++;
    }
    printf("%d\n",j);
}
}
开发者ID:ZxMYS,项目名称:Xiaos-ACM-Solution-Set,代码行数:24,代码来源:ROUND1A-A.cpp

示例6: assign

void assign(istringstream &iss, const string &str) {
	iss.clear();
	iss.str(str);
}
开发者ID:oerpli,项目名称:ComputationalPhysics,代码行数:4,代码来源:Functions.cpp


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