本文整理汇总了C++中stringstream::tellp方法的典型用法代码示例。如果您正苦于以下问题:C++ stringstream::tellp方法的具体用法?C++ stringstream::tellp怎么用?C++ stringstream::tellp使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类stringstream
的用法示例。
在下文中一共展示了stringstream::tellp方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: generate_output
void generate_output(const string& output_file_name,stringstream& output_str,bool force_output = false)
{
if( force_output || output_str.tellp() > 50 * 1024 * 1024 ){
FILE* fout = NULL;
if(flag_first_output){
fout = fopen(output_file_name.c_str(),"w");
flag_first_output = false;
}else{
fout = fopen(output_file_name.c_str(),"a");
}
string& str = output_str.str();
ElapasedTime time;
fwrite(str.c_str(),1,str.length(),fout);
fclose(fout);
cerr << "write to file time " << time.getTime() << "\n";
output_str.str(std::string());
output_str.clear();
}
}
示例2: handleRESTQuery
bool handleRESTQuery( OperationContext* txn,
const std::string& ns,
const std::string& action,
BSONObj & params,
int & responseCode,
stringstream & out ) {
Timer t;
int html = _getOption( params["html"] , 0 );
int skip = _getOption( params["skip"] , 0 );
int num = _getOption( params["limit"] , _getOption( params["count" ] , 1000 ) ); // count is old, limit is new
int one = 0;
if ( params["one"].type() == String && tolower( params["one"].valuestr()[0] ) == 't' ) {
num = 1;
one = 1;
}
BSONObjBuilder queryBuilder;
BSONObjIterator i(params);
while ( i.more() ) {
BSONElement e = i.next();
string name = e.fieldName();
if ( name.find( "filter_" ) != 0 )
continue;
string field = name.substr(7);
const char * val = e.valuestr();
char * temp;
// TODO: this is how i guess if something is a number. pretty lame right now
double number = strtod( val , &temp );
if ( temp != val )
queryBuilder.append( field , number );
else
queryBuilder.append( field , val );
}
BSONObj query = queryBuilder.obj();
DBDirectClient db(txn);
auto_ptr<DBClientCursor> cursor = db.query( ns.c_str() , query, num , skip );
uassert( 13085 , "query failed for dbwebserver" , cursor.get() );
if ( one ) {
if ( cursor->more() ) {
BSONObj obj = cursor->next();
out << obj.jsonString(Strict,html?1:0) << '\n';
}
else {
responseCode = 404;
}
return html != 0;
}
if( html ) {
string title = string("query ") + ns;
out << start(title)
<< p(title)
<< "<pre>";
}
else {
out << "{\n";
out << " \"offset\" : " << skip << ",\n";
out << " \"rows\": [\n";
}
int howMany = 0;
while ( cursor->more() ) {
if ( howMany++ && html == 0 )
out << " ,\n";
BSONObj obj = cursor->next();
if( html ) {
if( out.tellp() > 4 * 1024 * 1024 ) {
out << "Stopping output: more than 4MB returned and in html mode\n";
break;
}
out << obj.jsonString(Strict, html?1:0) << "\n\n";
}
else {
if( out.tellp() > 50 * 1024 * 1024 ) // 50MB limit - we are using ram
break;
out << " " << obj.jsonString();
}
}
if( html ) {
out << "</pre>\n";
if( howMany == 0 ) out << p("Collection is empty");
out << _end();
}
else {
out << "\n ],\n\n";
out << " \"total_rows\" : " << howMany << " ,\n";
out << " \"query\" : " << query.jsonString() << " ,\n";
out << " \"millis\" : " << t.millis() << '\n';
out << "}\n";
}
//.........这里部分代码省略.........