本文整理汇总了C++中ostringstream类的典型用法代码示例。如果您正苦于以下问题:C++ ostringstream类的具体用法?C++ ostringstream怎么用?C++ ostringstream使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ostringstream类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ofs
void
MrsLog::mrsMessage(const ostringstream& oss)
{
#ifdef MARSYAS_LOG_MESSAGES
if (!messages_off_)
{
#ifdef MARSYAS_LOG2STDOUT
cout << "[MRS_MESSAGE] " << oss.str() << endl;
#endif
#ifdef MARSYAS_LOG2STDERR
cerr << "[MRS_MESSAGE] " << oss.str() << endl;
#endif
#ifdef MARSYAS_LOG2FILE
ofstream ofs(fname_.c_str(), ios::out | ios::app);
if (ofs.fail())
return;
if (!(ofs << "[MRS_MESSAGE] " << oss.str() << endl))
{
ofs.close();
return;
}
ofs.close();
return;
#endif
}
#else
;
#endif
}
示例2: mutex_print
void mutex_print(ostringstream& oss)
{
pthread_mutex_lock(&mutex2);
cerr << oss.str();
oss.str("");
pthread_mutex_unlock(&mutex2);
}
示例3: compile
void compile(const std::vector<Sym>& syms, std::vector<single_function>& functions) {
symc_init();
static ostringstream os;
os.str("");
os << make_prototypes();
HashMap map(Sym::get_dag().size());
for (unsigned i = 0; i < syms.size(); ++i) {
os << "double func" << i << "(const double* x) { return ";
os << print_code(syms[i], map); //c_print(syms[i]);
os << ";}\n";
//symc_compile(os.str().c_str());
//cout << "compiling " << os.str() << endl;
}
os << ends;
#ifdef INTERVAL_DEBUG
//cout << "Compiling " << os.str() << endl;
#endif
symc_compile(os.str().c_str());
symc_link();
functions.resize(syms.size());
for (unsigned i = 0; i < syms.size(); ++i) {
ostringstream os2;
os2 << "func" << i;
functions[i] = (single_function) symc_get_fun(os2.str().c_str());
}
}
示例4: decode
result_t Message::decode(SymbolString& masterData, SymbolString& slaveData,
ostringstream& output, OutputFormat outputFormat,
bool leadingSeparator)
{
unsigned char offset = (unsigned char)(m_id.size() - 2);
size_t startPos = output.str().length();
result_t result = m_data->read(pt_masterData, masterData, offset, output, outputFormat, leadingSeparator, NULL, -1);
if (result < RESULT_OK)
return result;
bool empty = result == RESULT_EMPTY;
offset = 0;
leadingSeparator |= output.str().length() > startPos;
result = m_data->read(pt_slaveData, slaveData, offset, output, outputFormat, leadingSeparator, NULL, -1);
if (result < RESULT_OK)
return result;
if (result == RESULT_EMPTY && !empty)
result = RESULT_OK; // OK if at least one part was non-empty
time(&m_lastUpdateTime);
switch (masterData.compareMaster(m_lastMasterData)) {
case 1: // completely different
m_lastChangeTime = m_lastUpdateTime;
m_lastMasterData = masterData;
break;
case 2: // only master address is different
m_lastMasterData = masterData;
break;
}
if (slaveData != m_lastSlaveData) {
m_lastChangeTime = m_lastUpdateTime;
m_lastSlaveData = slaveData;
}
return result;
}
示例5: toString
string Text::toString(int n)
{
static ostringstream out;
out.str("");
out.clear();
out << n;
string newStr = out.str();
return newStr;
}
示例6: throw
void
CSipResponse::BuildPacket() throw(CSipException *)
{
if(GetCommand().length() == 0)
throw(new CSipException(SipError::UNSUPPORTED_COMMAND));
//
static ostringstream response;
response.clear();
response.str("");
//
if(GetCSeqCommand().length() == 0)
SetCSeqCommand(GetCommand());
//
response << "SIP/2.0" << GetStatusCode() << GetStatus() << " SIP/2.0\r\n"
<< "Via: SIP/2.0/UDP " << GetCallerAddress() << ":" << GetCallerPort()
<< ";branch=" << GetBranch() << "\r\n"
<< "Contact: <sip:" << GetCallerId() << "@" << GetCallerAddress()
<< ":" << GetCallerPort() << ">;expires=" << GetExpires() << "\r\n"
<< "Call-ID: " << GetCallId() << "\r\n"
<< "Cseq: " << GetCSeq() << " " << GetCSeqCommand() << "\r\n";
//
if(GetServer().length() > 0)
response << "Server: " << GetServer() << "\r\n";
//
// To field:
response << "To: ";
if(GetCalleeScreenName().length() > 0)
response << "\"" << GetCalleeScreenName() << "\"";
//
response << "<sip:" << GetCalleeId() << "@" << GetSipServerAddress() << ">";
response << ";tag=" << GetCalleeTag() << "\r\n";
//
// From field:
response << "From: ";
if(GetCallerScreenName().length() > 0)
response << "\"" << GetCallerScreenName() << "\"";
//
response << "<sip:" << GetCallerId() << "@" << GetCallerAddress() << ">"
<< ";tag=" << GetCallerTag() << "\r\n";
//
response << "Allow: REGISTER, INVITE, ACK, CANCEL, BYE\r\n";
//
if(GetContent().length() > 0)
{
response << "Content-Length: " << GetContent().length() << "\r\n"
<< "Content-Type: " << GetContentType() << "\r\n"
<< "\r\n" << GetContent();
}
else
response << "\r\n";
//
SetBuffer(response.str().c_str(), response.str().length());
}
示例7:
string header::double2str(const double in, const double missing_value)
{
if (in == missing_value)
return ".";
else
{
static ostringstream out;
out.str(""); out.clear();
out << in;
return out.str();
}
}
示例8: execute
/**
* This method will execute the given codeStream passed in.
* @param codeStream stream of C++ code that contains a compilable main() method
* @param force_rollback if set, this will rollback any changes made to the code
* during execution. This is used for the '!' and '@'
* commands.
* @return 0 if compilation is successful
*/
int execute(ostringstream* codeStream, bool force_rollback) {
int output = 0;
//Backup the main file before it gets overwritten by the code stream.
backup_file(sMainPath);
//Write the code stream to the main file.
ofstream outputFile;
outputFile.open(sMainPath.c_str());
outputFile << codeStream->str();
outputFile.close();
//Backup the current executable before compiling.
backup_file(sExecPath);
//Attempt to compile
output = compile();
if (output == 0) {
//If compiling is successful, get the full path of the executable and send
//it to system() to compile.
char full_path[256];
realpath(sExecPath.c_str(), full_path);
system(full_path);
}
//Rollback if force flag is set, or if compilation failed.
if ((force_rollback) || (output != 0)) {
rollback_file(sMainPath);
output=1;
}
//Rollback the executable after it is done. This is to prevent a project
//executable from getting modified. This only applies when the console in
//running in a project directory.
rollback_file(sExecPath);
//Reset variables now that the code was executed.
sCodeBuffer.str(""); //Clear out the code buffer to allow new user input.
sCodeBuffer.clear();
sCodeType = MAIN_CODE; //Reset the code type to its default.
sBraceCount = 0; //Ensure the brace count is zero. A reload! can force an
//execution even if the brace count is not zero.
//Ensure a newline is printed since the output may not have one.
cout << "\n";
return output;
}
示例9: buildURLGoogle
void buildURLGoogle(const axutil_env_t* env,axis2_char_t* symbol,axutil_date_time_t* start, axutil_date_time_t* end,ostringstream& oss)
{
int syear = axutil_date_time_get_year(start,env);
int smonth = axutil_date_time_get_month(start,env);
int sdate = axutil_date_time_get_date(start,env);
int eyear = axutil_date_time_get_year(end,env);
int emonth = axutil_date_time_get_month(end,env);
int edate = axutil_date_time_get_date(end,env);
oss.str("");
oss<<"http://www.google.com/finance/historical?q=";
oss<<symbol<<"&startdate=";
oss<<GlobalVariables::m_months[smonth]<<"+"<<sdate<<"%2C+"<<syear<<"&enddate=";
oss<<GlobalVariables::m_months[emonth]<<"+"<<edate<<"%2C+"<<eyear<<"&histperiod=weekly&num=30&output=csv";
AXIS2_LOG_INFO(env->log,"build url google version [%s]",oss.str().c_str());
}
示例10: broadCast
/**
Sends messages to all clients or to all clients not in a game.
*/
void broadCast(bool global){
verbose && cout << ticks() << ": server broadcasts: .:" << buffer.str() <<":." << endl;
for (Clients::iterator it = clients.begin(); it != clients.end(); it++) if (it->second != 0){
if (it->second && ((global) || (it->second->game == 0))) it->second->cast();
}
buffer.str("");
}
示例11: listAllParticipateMeetings
void AgendaUI::listAllParticipateMeetings(void) {
cout << endl << "****************" << endl << "listAllParticipateMeetings" << endl << "***************" << endl;
os << endl;
os << "[list all participator meetings]" << endl;
os << endl;
os << left << setw(17) << "title";
os << left << setw(17) << "sponsor";
os << left << setw(17) << "participator";
os << left << setw(17) << "start time";
os << left << setw(17) << "end time" << endl;
list<Meeting> l = agendaService_.listAllParticipateMeetings(userName_);
for (list<Meeting>::iterator it = l.begin(); it != l.end(); it++) {
os << left << setw(17) << it->getTitle();
os << left << setw(17) << it->getSponsor();
os << left << setw(17) << it->getParticipator();
os << left << setw(17) << Date::dateToString(it->getStartDate());
os << left << setw(17) << Date::dateToString(it->getEndDate()) << endl;
}
os << endl;
os << endl;
os << "[email protected]" << userName_ << " : # ";
res = os.str();
strcpy(buffer, res.c_str());
os.str("");
__send();
input();
}
示例12: deleteUser
void AgendaUI::deleteUser(void) {
cout << endl << "****************" << endl << "deleteUser" << endl << "***************" << endl;
if (agendaService_.deleteUser(userName_, userPassword_)) {
os << "[delete agenda account] succeed!" << endl;
os << "--------------------------------Agenda--------------------------------" << endl;
os << "Action :" << endl;
os << "l - log in Agenda by user name and password" << endl;
os << "r - register an Agenda account" << endl;
os << "q - quit Agenda" << endl;
os << "help- show the operation list" << endl;
os << "----------------------------------------------------------------------" << endl;
os << endl;
os << "Agenda : ~$ ";
res = os.str();
strcpy(buffer, res.c_str());
os.str("");
__send();
start_input();
} else {
os << "[error] delete agenda acount fail!" << endl;
os << endl;
os << "[email protected]" << userName_ << " : # ";
res = os.str();
strcpy(buffer, res.c_str());
os.str("");
__send();
input();
}
}
示例13: start_input
void AgendaUI::start_input() {
cout << endl << "****************" << endl << "start_input" << endl << "***************" << endl;
// os << endl;
// os << "Agenda : ~$ ";
// res = os.str(); strcpy(buffer, res.c_str()); os.str(""); __send();
while(1) {
string op = getOperation();
if(op == "l" || op == "r" || op == "q" || op == "help") {
if (op == "help") {
executeOperation("help_start");
} else {
executeOperation(op);
}
break;
} else {
os << "your enter is wrong please enter again" << endl;
os << endl;
os << "Agenda : ~$ ";
res = os.str();
strcpy(buffer, res.c_str());
os.str("");
__send();
start_input();
break;
}
}
}
示例14: get_round
string get_round(int i) {
string ret = NO_ROUND;
char buff[100];
sprintf(buff, "https://old.jutge.org/competitions/AlbertAtserias:BolaDeDrac2015/round/%d", i);
string url = buff;
request.setOpt(curlpp::options::Url(url));
request.perform();
string re = responseStream.str();
size_t found = re.find("Player out:");
if (found != string::npos) {
size_t inici = re.find("<p class='indent'>",found+1);
size_t fi = re.find("(",found+1);
cout << " --> ";
if (inici != string::npos and fi != string::npos) {
ret = re.substr(inici+18, fi-(inici+18));
cout << ret << endl;
}
} else if (re.find("Turn 1") != string::npos) {
ret = ONGOING;
}
responseStream.str(string());
return ret;
}
示例15: quitAgenda
void AgendaUI::quitAgenda(void) {
os << "quit";
res = os.str();
strcpy(buffer, res.c_str());
os.str("");
__send();
agendaService_.quitAgenda();
}