本文整理汇总了C++中st::string::length方法的典型用法代码示例。如果您正苦于以下问题:C++ string::length方法的具体用法?C++ string::length怎么用?C++ string::length使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类st::string
的用法示例。
在下文中一共展示了string::length方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: droprun
void droprun(dataobject & o)
{
list<ST::string> names = o.m.getModelVarnames();
ST::string boolexp = o.methods[1].getexpression();
if ( (names.size() > 0) && (boolexp.length() == 0) )
{
o.d.dropvariables(names);
o.errormessages = o.d.geterrormessages();
if (o.errormessages.empty())
o.out("NOTE: " + ST::inttostring(names.size()) + " variables dropped\n");
}
else if ( (names.size() == 0) && (boolexp.length() > 0) )
{
unsigned nrelim;
nrelim = o.d.dropobservations(boolexp);
o.errormessages = o.d.geterrormessages();
if (o.errormessages.empty())
o.out("NOTE: " + ST::inttostring(nrelim) + " observations dropped\n");
}
else if ( (names.size() == 0) && (boolexp.length() == 0) )
{
o.outerror("ERROR: varlist or boolean expression expected\n");
}
else
o.outerror("ERROR: dropping variables and observations in one step not allowed\n");
o.changedescription();
}
示例2: parse
void usePathWrite::parse(const ST::string & usetext)
{
path = "";
errormessages.clear();
notext = true;
if (usetext.length() > 0)
{
notext = false;
int k = usetext.isvalidfile();
if (k == 1)
{
errormessages.push_back("ERROR: file " + usetext +
" could not be opened for writing\n");
alreadyexisting = false;
}
else if (k == 0)
alreadyexisting = false;
else
alreadyexisting = true;
if (errormessages.empty())
path = usetext;
}
}
示例3: outfilerun
void outfilerun(dataobject & o)
{
unsigned nrwritten;
ST::string path = o.uwrite.getPath();
list<ST::string> names = o.m.getModelVarnames();
ST::string expression = o.methods[6].getexpression();
if ( (o.uwrite.isexisting() == true) && (o.replace.getvalue() == false) )
o.errormessages.push_back(
"ERROR: file " + path + " is already existing\n");
else
{
ofstream fout;
ST::open(fout,path);
if (expression.length() > 0)
{
realvar v = o.d.eval_exp(expression);
#if defined(JAVA_OUTPUT_WINDOW)
nrwritten = o.d.write(o.adminb_p,fout,names,o.header.getvalue(),v);
#else
nrwritten = o.d.write(fout,names,o.header.getvalue(),v);
#endif
}
else
{
#if defined(JAVA_OUTPUT_WINDOW)
nrwritten = o.d.write(o.adminb_p,fout,names,o.header.getvalue());
#else
nrwritten = o.d.write(fout,names,o.header.getvalue());
#endif
}
o.errormessages = o.d.geterrormessages();
if (o.errormessages.empty())
{
o.out("NOTE: " + ST::inttostring(names.size()) + " variable(s) with " +
ST::inttostring(nrwritten) + " observations written to file\n");
o.out(" " + path + "\n");
}
else
{
fout.close();
remove(path.strtochar());
}
}
}
示例4: outresults
void FC_nonp_variance_varselection::outresults(ofstream & out_stata,ofstream & out_R,
const ST::string & pathresults)
{
if (pathresults.isvalidfile() != 1)
{
ST::string pathresults_delta = pathresults.substr(0,pathresults.length()-4) + "_delta.res";
ST::string pathresults_omega = pathresults.substr(0,pathresults.length()-4) + "_omega.res";
FC_nonp_variance::outresults(out_stata,out_R,pathresults);
FC_delta.outresults(out_stata,out_R,"");
FC_omega.outresults(out_stata,out_R,pathresults_omega);
optionsp->out(" Inclusion probability: " + ST::doubletostring(FC_delta.betamean(0,0),6) + "\n");
optionsp->out("\n");
optionsp->out(" Results for the inclusion probabilities are also stored in file\n");
optionsp->out(" " + pathresults_delta + "\n");
optionsp->out("\n");
optionsp->out("\n");
optionsp->out(" Inclusion probability parameter omega:\n");
optionsp->out("\n");
FC_omega.outresults_singleparam(out_stata,out_R,"");
optionsp->out(" Results for the inclusion probability parameter omega are also stored in file\n");
optionsp->out(" " + pathresults_omega + "\n");
optionsp->out("\n");
optionsp->out("\n");
// deltas
ofstream ou(pathresults_delta.strtochar());
ou << "pmean" << endl;
ou << FC_delta.betamean(0,0) << endl;
}
// FC_nonp_variance::outresults(out_stata,out_R,pathresults);
}
示例5: outresults_deviance
void FC_predict_mult::outresults_deviance(void)
{
ST::string l1 = ST::doubletostring(optionsp->lower1,4);
ST::string l2 = ST::doubletostring(optionsp->lower2,4);
ST::string u1 = ST::doubletostring(optionsp->upper1,4);
ST::string u2 = ST::doubletostring(optionsp->upper2,4);
l1 = l1.replaceallsigns('.','p');
l2 = l2.replaceallsigns('.','p');
u1 = u1.replaceallsigns('.','p');
u2 = u2.replaceallsigns('.','p');
ST::string meanstr = " Mean: ";
unsigned l_meanstr = meanstr.length();
ST::string stdstr = " Std. Dev: ";
unsigned l_stdstr = stdstr.length();
ST::string l1str = " " + l1 + "% Quantile: ";
unsigned l_l1str = l1str.length();
ST::string l2str = " " + l2 + "% Quantile: ";
unsigned l_l2str = l2str.length();
ST::string medianstr = " 50% Quantile: ";
unsigned l_medianstr = medianstr.length();
ST::string u1str = " " + u1 + "% Quantile: ";
unsigned l_u1str = u1str.length();
ST::string u2str = " " + u2 + "% Quantile: ";
unsigned l_u2str = u2str.length();
optionsp->out(" ESTIMATION RESULT FOR THE DEVIANCE: \n",true);
optionsp->out("\n");
double devhelpm = FC_deviance.betamean(0,0);
double devhelp;
unsigned d;
if (devhelpm > 1000000000)
d = 14;
else if (devhelpm > 1000000)
d = 11;
else
d = 8;
optionsp->out(meanstr + ST::string(' ',20-l_meanstr) +
ST::doubletostring(devhelpm,d) + "\n");
devhelp = sqrt(FC_deviance.betavar(0,0));
optionsp->out(stdstr + ST::string(' ',20-l_stdstr) +
ST::doubletostring(devhelp,d) + "\n");
devhelp = FC_deviance.betaqu_l1_lower(0,0);
optionsp->out(l1str + ST::string(' ',20-l_l1str) +
ST::doubletostring(devhelp,d) + "\n");
devhelp = FC_deviance.betaqu_l2_lower(0,0);
optionsp->out(l2str + ST::string(' ',20-l_l2str) +
ST::doubletostring(devhelp,d) + "\n");
devhelp = FC_deviance.betaqu50(0,0);
optionsp->out(medianstr + ST::string(' ',20-l_medianstr) +
ST::doubletostring(devhelp,d) + "\n");
devhelp = FC_deviance.betaqu_l2_upper(0,0);
optionsp->out(u1str + ST::string(' ',20-l_u1str) +
ST::doubletostring(devhelp,d) + "\n");
devhelp = FC_deviance.betaqu_l1_upper(0,0);
optionsp->out(u2str + ST::string(' ',20-l_u2str) +
ST::doubletostring(devhelp,d) + "\n");
optionsp->out("\n");
optionsp->out("\n");
}
示例6: outresults_DIC
void FC_predict_mult::outresults_DIC(ofstream & out_stata, ofstream & out_R,
const ST::string & pathresults)
{
ST::string pathresultsdic = pathresults.substr(0,pathresults.length()-4) + "_DIC.res";
ofstream out(pathresultsdic.strtochar());
out_R << "DIC=" << pathresultsdic << ";" << endl;
optionsp->out(" Results for the DIC are stored in file\n");
optionsp->out(" " + pathresultsdic + "\n");
optionsp->out("\n");
double deviance2=0;
double devhelp;
vector<double *> worklinp;
vector<double *> workresponse;
vector<double *> workweight;
vector<datamatrix *> aux;
unsigned j;
for (j=0;j<likep.size();j++)
{
worklinp.push_back(betamean.getV()+j);
workresponse.push_back(likep[j]->response.getV());
workweight.push_back(likep[j]->weight.getV());
aux.push_back(likep[j]->get_auxiliary_parameter(auxpostmean));
}
unsigned i;
for (i=0;i<likep[0]->nrobs;i++)
{
likep[likep.size()-1]->compute_deviance_mult(workresponse,
workweight,worklinp,
&devhelp,aux);
deviance2 += devhelp;
int s = likep.size();
int bs = betamean.cols();
for (j=0;j<s;j++)
{
worklinp[j]+=bs;
workresponse[j]++;
workweight[j]++;
}
}
double devhelpm = FC_deviance.betamean(0,0);
unsigned d;
if (devhelpm > 1000000000)
d = 14;
else if (devhelpm > 1000000)
d = 11;
else
d = 8;
out << "deviance pd dic" << endl;
optionsp->out(" ESTIMATION RESULTS FOR THE DIC: \n",true);
optionsp->out("\n");
optionsp->out(" Deviance(bar_mu): " +
ST::doubletostring(deviance2,d) + "\n");
out << deviance2 << " ";
optionsp->out(" pD: " +
ST::doubletostring(devhelpm-deviance2,d) + "\n");
out << (devhelpm-deviance2) << " ";
optionsp->out(" DIC: " +
ST::doubletostring(2*devhelpm-deviance2,d) + "\n");
optionsp->out("\n");
out << (2*devhelpm-deviance2) << " " << endl;
optionsp->out("\n");
}
示例7: parse
bool administrator::parse(ST::string & in)
{
errormessages.clear();
ST::string objectname;
ST::string firsttoken = in.getFirstToken(" .");
int pointpos = in.checksign('.');
if (firsttoken.length() > 0)
{
if ( (firsttoken == "quit") || (firsttoken == "exit") )
return true;
else if (firsttoken == "delimeter")
{
vector<ST::string> token = in.strtoken(" ");
if (token.size() != 3)
errormessages.push_back("ERROR: invalid syntax\n");
else if (token[1] != "=")
errormessages.push_back("ERROR: \"=\" expected\n");
else
{
if (token[2] == "newline")
delim = '\n';
else if (token[2].length() > 1)
errormessages.push_back("ERROR: invalid delimeter symbol\n");
else
delim = token[2][0];
}
return false;
} // end: delimeter
else if (firsttoken == "usefile")
{
vector<ST::string> token = in.strtoken(" ");
if (token.size() < 2)
errormessages.push_back("ERROR: filename expected\n");
else if (token.size() > 2)
errormessages.push_back("ERROR: invalid syntax\n");
if (errormessages.empty())
{
ST::string path = token[1];
if (path.isexistingfile() == 1)
errormessages.push_back("ERROR: file " + path +
" could not be opened\n");
else
{
ST::string in;
ifstream infile;
input = &infile;
ST::open(infile,path);
while (! infile.eof())
{
ST::getline(infile,10000,in,delim);
if (delim != '\n')
in = in.replaceallsigns('\n',' ');
in = in.eatwhitespace();
out("> " + in + "\n");
parse(in);
}
}
}
input = &cin;
out(errormessages);
return false;
}
else if (firsttoken == "logopen")
{
model m;
simpleoption replace("replace",false);
optionlist logoptions;
logoptions.push_back(&replace);
usePathWrite uw;
command logopen("logopen",&m,&logoptions,&uw,notallowed,notallowed,
notallowed,notallowed,optional,required);
logopen.parse(in);
errormessages = logopen.geterrormessages();
if (logfileopen == true)
errormessages.push_back("ERROR: logfile is already open\n");
if (errormessages.empty())
{
logfileopen = true;
logfilepath = uw.getPath();
if ((replace.getvalue() == false) && (uw.isexisting() == true))
{
ST::open(logout,logfilepath,ios::app);
}
else
{
ST::open(logout,logfilepath);
}
//.........这里部分代码省略.........
示例8: outresults
void FC_cv::outresults(ofstream & out_stata, ofstream & out_R,
const ST::string & pathresults)
{
if (pathresults.isvalidfile() != 1)
{
FC::outresults(out_stata,out_R,pathresults);
optionsp->out(" Marshall-Spiegelhalter Cross Validation: \n",true);
optionsp->out("\n");
optionsp->out(" Estimated individual observation samples are stored in\n");
optionsp->out(" " + pathresults + "\n");
optionsp->out("\n");
ST::string pathresults_like = pathresults.substr(0,pathresults.length()-4)+
"_like.res";
FC_sampled_l.outresults(out_stata,out_R,pathresults_like);
optionsp->out(" Estimated individual observation likelihoods are stored in\n");
optionsp->out(" " + pathresults_like + "\n");
optionsp->out("\n");
// unsigned nrobs = sampled_etas.rows();
unsigned i;
/*
ofstream outres(pathresults.strtochar());
for(j=0;j<sampled_etas.cols();j++)
outres << "s_eta_" << (j+1) << " ";
for(j=0;j<sampled_etas.cols();j++)
outres << "s_resp_" << (j+1) << " ";
outres << endl;
for (i=0;i<nrobs;i++)
{
for(j=0;j<sampled_etas.cols();j++)
outres << sampled_etas(i,j) << " ";
for(j=0;j<sampled_responses.cols();j++)
outres << sampled_responses(i,j) << " ";
outres << endl;
}
*/
// Energy score
double es = compute_energyscore();
ST::string pathresults_e = pathresults.substr(0,pathresults.length()-4)+
"_energy.res";
ofstream out2(pathresults_e.strtochar());
out2 << "id score" << endl;
for (i=0;i<e_score.rows();i++)
out2 << effectvalues[i] << " " << e_score(i,0) << endl;
// Log-score
double ls = compute_logscore();
ST::string pathresults_l = pathresults.substr(0,pathresults.length()-4)+
"_logscore.res";
ofstream out3(pathresults_l.strtochar());
out3 << "id score" << endl;
for (i=0;i<e_score.rows();i++)
out3 << effectvalues[i] << " " << log_score(i,0) << endl;
optionsp->out(" Estimated energy scores are stored in\n");
optionsp->out(" " + pathresults_e + "\n");
optionsp->out("\n");
optionsp->out(" Estimated log-scores are stored in\n");
optionsp->out(" " + pathresults_l + "\n");
optionsp->out("\n");
optionsp->out(" Mean energy score: " + ST::doubletostring(es,8) + "\n");
optionsp->out(" Mean log score: " + ST::doubletostring(ls,8) + "\n");
} // end if (pathresults.isvalidfile() != 1)
//.........这里部分代码省略.........