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


C++ string::substr方法代码示例

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


在下文中一共展示了string::substr方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: cdUp

ST::string cdUp(ST::string path) {
    // Check for root paths, we can't go up from there!
#ifdef _WIN32
    if (path.substr(1) == ":\\")
        return path;
#else
    if (path == "/")
        return path;
#endif

    // Not very robust, but it works for one level of parent scanning
    if (path.is_empty())
        return ".." PATHSEPSTR;

    // Strip the ending slash, if necessary, and then go up one dir
    if (path.char_at(path.size()-1) == PATHSEP)
        path = path.left(path.size() - 1);
    ST::string up = path.before_last(PATHSEP);
    if (path.char_at(0) == PATHSEP) {
        // Absolute path specified -- make sure we keep it that way
        return up + PATHSEPSTR;
    } else {
        // Relative path specified
        return up.is_empty() ? "" : up + PATHSEPSTR;
    }
}
开发者ID:Lunanne,项目名称:libhsplasma,代码行数:26,代码来源:PlasmaSum.cpp

示例2: filenameConvert

ST::string filenameConvert(const ST::string& filename, eDirection dir) {
    if (dir == kRepack) {
        fputs("Zrax broke me!\n", stderr);
        abort();
    }
    ST::string newName = filename;
    ST_ssize_t dotLoc = newName.find_last('.');
    if (dotLoc < 0) {
        newName += (dir == kCreate) ? ".prp" : ".prd";
    } else if (dir == kCreate) {
        ST::string ext = newName.substr(dotLoc);
        if (ext == ".prd")
            newName.replace(".prd", ".prp");
        else if (ext != ".prp")
            newName += ".prp";
    } else {
        ST::string ext = newName.substr(dotLoc);
        if (ext == ".prp")
            newName.replace(".prp", ".prd");
        else if (ext != ".prd")
            newName += ".prd";
    }
    return newName;
}
开发者ID:Deledrius,项目名称:libhsplasma,代码行数:24,代码来源:PrpPack.cpp

示例3: 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);

  }
开发者ID:jfahren,项目名称:BayesX,代码行数:42,代码来源:FC_nonp_variance.cpp

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

  }
开发者ID:jfahren,项目名称:BayesX,代码行数:92,代码来源:FC_predict_mult.cpp

示例5: main

int main(int argc, char* argv[]) {
    if (argc < 2 || argc > 3) {
        doHelp();
        return 0;
    }

    eDirection direction = kRepack;
    ST::string filename = argv[1];
    ST_ssize_t dotLoc = filename.find_last('.');
    if (argc == 3) {
        if (strcmp(argv[1], "-c") == 0)
            direction = kCreate;
        else if (strcmp(argv[1], "-x") == 0)
            direction = kExtract;
        else if (strcmp(argv[1], "-r") == 0)
            direction = kRepack;
        else {
            doHelp();
            return 1;
        }
        filename = argv[2];
    } else if (dotLoc >= 0 && filename.substr(dotLoc) == ".prd") {
        direction = kCreate;
    }

    plResManager rm;
    hsFileStream S, OS;
    if (!S.open(filename, fmRead)) {
        ST::printf(stderr, "Error opening {} for reading!", filename);
        return 1;
    }
    plPageInfo* page = new plPageInfo();

    //int len;
    short maj = 63, min = 11;
    unsigned int i, j;
    if (direction == kExtract || direction == kRepack) {
        S.close();
        delete page;
        page = rm.ReadPage(filename, true);
        OS.open(filenameConvert(filename, kExtract), fmCreate);
        OS.write(4, "PRD");
        OS.writeShort(page->getAge().size());
        OS.writeStr(page->getAge());
        OS.writeShort(page->getPage().size());
        OS.writeStr(page->getPage());
        if (rm.getVer().isUniversal()) {
            maj = 0x7FFF;
            min = 0x7FFF;
        } else  if (rm.getVer().isEoa()) {
            maj = -1;
            min = 1;
        } else if (rm.getVer().isHexIsle()) {
            maj = -1;
            min = 2;
        } else {
            maj = rm.getVer().revMajor();
            min = rm.getVer().revMinor();
        }
        OS.writeShort(maj);
        OS.writeShort(min);
        plLocation loc = page->getLocation();
        loc.write(&OS);
        OS.close();

        std::vector<short> types = rm.getTypes(loc);
      #ifdef _WIN32
        CreateDirectoryW(getOutputDir(filename, page).to_wchar().data(), NULL);
      #else
        mkdir(getOutputDir(filename, page).c_str(), S_IRWXU|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH);
      #endif
        for (i=0; i<types.size(); i++) {
            std::vector<plKey> objs = rm.getKeys(loc, types[i]);
            for (j=0; j<objs.size(); j++) {
                ST::string po_file = ST::format("{}[{04X}]{}.po", getOutputDir(filename, page),
                                                types[i], CleanFileName(objs[j]->getName()));
                OS.open(po_file, fmCreate);
                OS.setVer(rm.getVer());
                rm.WriteCreatable(&OS, objs[j]->getObj());
                OS.close();
            }
        }
    }
    if (direction == kRepack) {
        filename = filenameConvert(filename, kExtract);
        S.open(filename, fmRead);
    }
    if (direction == kCreate || direction == kRepack) {
        OS.open(filenameConvert(filename, kCreate), fmCreate);
        char sig[4];
        S.read(4, sig);
        if (strncmp(sig, "PRD", sizeof(sig)) != 0) {
            fputs("Error: Invalid input file!\n", stderr);
            OS.close();
            S.close();
            return 1;
        }
        ST::string ageName = S.readStr(S.readShort());
        ST::string pageName = S.readStr(S.readShort());
        page->setAge(ageName);
//.........这里部分代码省略.........
开发者ID:Deledrius,项目名称:libhsplasma,代码行数:101,代码来源:PrpPack.cpp

示例6: parse


//.........这里部分代码省略.........
		  out(errormessages);
		  }
		else
		  {
		  logfileopen = false;
		  logout.close();
		  out("NOTE: logfile " + logfilepath + " closed\n");
		  }
		return false;
		}  // end: logclose
	 else if (firsttoken == "drop")
		{

		modelStandard m;
		optionlist dropoptions;
		usePathWrite uw;

		command drop("drop",&m,&dropoptions,&uw,required,notallowed,
							 notallowed,notallowed,notallowed,notallowed);

		drop.parse(in);
		errormessages = drop.geterrormessages();
		vector<ST::string> objectnames =  m.getModelVarnamesAsVector();
		if (objectnames.size() == 0)
		  errormessages.push_back("ERROR: objectlist required\n");

		if (errormessages.empty())
		  {

		  int j;
		  for (j=0;j<objectnames.size();j++)
			 {

			 int recognized = 0;
			 int i=0;
			 while ( (i < objects.size()) && (recognized == 0) )
				{

				if ( objectnames[j] == objects[i]->getname())
				  {
				  ST::string type = objects[i]->gettype();
				  dropobjects(objectnames[j],type);
				  recognized = 1;
				  }
				i++;
				}

			  if (recognized == 0)
				 errormessages.push_back(
				 "ERROR: object " + objectnames[j] + " is not existing\n");

			 } // end: for (j=0;j<objectnames.size();j++)

		  }  // end: if (errormessages.empty())

		out(errormessages);
		return false;
		} // end: drop
	 else if (firsttoken.isinlist(objecttyps) >= 0)      // create a new object
		{


		if (pointpos == -1)
		  objectname = create(in);
		else
		  objectname = create(in.substr(0,pointpos));


		if ( (errormessages.empty()) && (pointpos > 0) )
		  {
		  if (in.length()-1-pointpos <= 0)
			 errormessages.push_back("ERROR: invalid syntax\n");
		  else
			parseexisting(objectname,in.substr(pointpos+1,in.length()-1-pointpos));
		  }

		out(errormessages);
		return false;

		}               // end: create a new object
	 else     // existing object
		{
		if (pointpos != firsttoken.length())
		  errormessages.push_back("ERROR: invalid syntax\n");
		else
		  if (in.length() > pointpos+1)
			parseexisting(firsttoken,in.substr(pointpos+1,in.length()-pointpos-1));
		  else
			 errormessages.push_back("ERROR: invalid syntax\n");

		out(errormessages);
		return false;

		}

	 }  // end: if (firsttoken.length() > 0)
  else                                                  // empty command
	 return false;

  }
开发者ID:cran,项目名称:BayesXsrc,代码行数:101,代码来源:admin.cpp

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

//.........这里部分代码省略.........
开发者ID:jfahren,项目名称:BayesX,代码行数:101,代码来源:FC_cv.cpp


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