本文整理汇总了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;
}
示例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;
}
示例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 ;
}
示例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;
}
示例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);
}
}
示例6: assign
void assign(istringstream &iss, const string &str) {
iss.clear();
iss.str(str);
}