您当前的位置:首页 > IT编程 > C++
| C语言 | Java | VB | VC | python | Android | TensorFlow | C++ | oracle | 学术与代码 | cnn卷积神经网络 | gnn | 图像修复 | Keras | 数据集 | Neo4j | 自然语言处理 | 深度学习 | 医学CAD | 医学影像 | 超参数 | pointnet | pytorch | 异常检测 | Transformers | 情感分类 | 知识图谱 |

自学教程:C++ string函数代码示例

51自学网 2021-06-03 08:29:52
  C++
这篇教程C++ string函数代码示例写得很实用,希望能帮到您。

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

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

示例1: rand_r

void ItemsMaker::doWork(){    int r = rand_r(&m_randSeed);    r = r % (int)m_sleepMs();    int first = -1;    string bucket;    ItemsListPtr items;    {        boost::lock_guard<boost::mutex> lock(g_data.m_mutex);        if (g_data.m_buckets.empty()) {            return;        }        int n = r % g_data.m_buckets.size();        BucketsMap::iterator iter = g_data.m_buckets.begin();        for (int i = 0; iter != g_data.m_buckets.end(); i++, iter++) {            if (i == n) {                break;            }        }        if (iter == g_data.m_buckets.end()) {            cout << "ItemsMaker: Failed to find bucket" << endl;            return;        }        bucket = iter->first;        items = iter->second;        if (!items->empty()) {            first = *items->begin();        }    }    if (r < m_multipliyer() * m_reconnectProbability()) {        m_sock.disconnect();        sleepMs(20);        m_sock.connect("localhost", m_port);    }    int prob = m_multipliyer() * m_createProbability();    if (r < prob) {        // Add item        string cmd = string("create ") + bucket + " 1111";        execCommand(m_sock, cmd, m_buffer);        int id;        int n = sscanf(m_buffer.raw(), "%d", &id);        if (n == 1) {            boost::lock_guard<boost::mutex> lock(g_data.m_mutex);            items->push_back(id);        }        else {            //cout << "Failed to add item: " << m_buffer.raw() << endl;        }        return;    }    prob += m_multipliyer() * m_deleteProbability();    if (r < prob && !items->empty()) {        // Delete item        string cmd = string("delete ") + bucket + " " + boost::lexical_cast<string>(first);        execCommand(m_sock, cmd, m_buffer);        if (strcmp(m_buffer.raw(), "ok") == 0) {            boost::lock_guard<boost::mutex> lock(g_data.m_mutex);            if (*items->begin() == first) {                items->erase(items->begin());            }        }        else {            //cout << "Failed to delete item: " << m_buffer.raw() << endl;        }        return;    }    prob += m_multipliyer() * m_updateProbability();    if (r < prob && !items->empty()) {        // Update item        string cmd = string("update ") + bucket + " " + boost::lexical_cast<string>(first) + " 2222";        execCommand(m_sock, cmd, m_buffer);        if (strcmp(m_buffer.raw(), "ok") != 0) {            //cout << "Failed to update item: " << m_buffer.raw() << endl;        }        return;    }    prob += m_multipliyer() * m_readProbability();    if (r < prob && !items->empty()) {        // Read item        string cmd = string("read ") + bucket + " " + boost::lexical_cast<string>(first);        execCommand(m_sock, cmd, m_buffer);    }    prob += m_multipliyer() * m_invalidProbability();    if (r < prob && !items->empty()) {        // Invalid command        string cmd = string("invalide command");//.........这里部分代码省略.........
开发者ID:michael-popov,项目名称:clockwork,代码行数:101,


示例2: run

        virtual bool run(const string& , BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool fromRepl) {            log() << "replSet replSetInitiate admin command received from client" << rsLog;            if( !replSet ) {                errmsg = "server is not running with --replSet";                return false;            }            if( theReplSet ) {                errmsg = "already initialized";                result.append("info", "try querying " + rsConfigNs + " to see current configuration");                return false;            }            {                // just make sure we can get a write lock before doing anything else.  we'll reacquire one                // later.  of course it could be stuck then, but this check lowers the risk if weird things                // are up.                time_t t = time(0);                Lock::GlobalWrite lk;                if( time(0)-t > 10 ) {                    errmsg = "took a long time to get write lock, so not initiating.  Initiate when server less busy?";                    return false;                }                /* check that we don't already have an oplog.  that could cause issues.                   it is ok if the initiating member has *other* data than that.                   */                BSONObj o;                if( Helpers::getFirst(rsoplog, o) ) {                    errmsg = rsoplog + string(" is not empty on the initiating member.  cannot initiate.");                    return false;                }            }            if( ReplSet::startupStatus == ReplSet::BADCONFIG ) {                errmsg = "server already in BADCONFIG state (check logs); not initiating";                result.append("info", ReplSet::startupStatusMsg.get());                return false;            }            if( ReplSet::startupStatus != ReplSet::EMPTYCONFIG ) {                result.append("startupStatus", ReplSet::startupStatus);                errmsg = "all members and seeds must be reachable to initiate set";                result.append("info", cmdLine._replSet);                return false;            }            BSONObj configObj;            if( cmdObj["replSetInitiate"].type() != Object ) {                result.append("info2", "no configuration explicitly specified -- making one");                log() << "replSet info initiate : no configuration specified.  Using a default configuration for the set" << rsLog;                string name;                vector<HostAndPort> seeds;                set<HostAndPort> seedSet;                parseReplsetCmdLine(cmdLine._replSet, name, seeds, seedSet); // may throw...                bob b;                b.append("_id", name);                bob members;                members.append("0", BSON( "_id" << 0 << "host" << HostAndPort::me().toString() ));                result.append("me", HostAndPort::me().toString());                for( unsigned i = 0; i < seeds.size(); i++ )                    members.append(bob::numStr(i+1), BSON( "_id" << i+1 << "host" << seeds[i].toString()));                b.appendArray("members", members.obj());                configObj = b.obj();                log() << "replSet created this configuration for initiation : " << configObj.toString() << rsLog;            }            else {                configObj = cmdObj["replSetInitiate"].Obj();            }            bool parsed = false;            try {                scoped_ptr<ReplSetConfig> newConfig(ReplSetConfig::make(configObj));                parsed = true;                if( newConfig->version > 1 ) {                    errmsg = "can't initiate with a version number greater than 1";                    return false;                }                log() << "replSet replSetInitiate config object parses ok, " <<                        newConfig->members.size() << " members specified" << rsLog;                checkMembersUpForConfigChange(*newConfig, result, true);                log() << "replSet replSetInitiate all members seem up" << rsLog;                createOplog();                Lock::GlobalWrite lk;                bo comment = BSON( "msg" << "initiating set");                newConfig->saveConfigLocally(comment);                log() << "replSet replSetInitiate config now saved locally.  Should come online in about a minute." << rsLog;                result.append("info", "Config now saved locally.  Should come online in about a minute.");                ReplSet::startupStatus = ReplSet::SOON;                ReplSet::startupStatusMsg.set("Received replSetInitiate - should come online shortly.");                // Dummy minvalid - just something non-null so we can be "up"//.........这里部分代码省略.........
开发者ID:KevinEtienne,项目名称:mongo,代码行数:101,


示例3: getEventContainer

//React on events from METKManagervoid METKAutoFading::handleObjMgrNotification(){		omEventContainer myEventList = getEventContainer();	//Durchiterieren der EventList	omEventContainer::const_iterator iter;			for ( iter = myEventList.begin();iter!=myEventList.end(); iter++)	{		ObjMgrEvent myEvent = (*iter);		if (myEvent.layerID == LAY_VIEWER_CAMERA && myEvent.infoID == INF_VIEWER_CAMERA_POSITION && _EnableFading->getBoolValue() && _UseMETKValues->getBoolValue() )		{				_calc->notify();		}		else if (myEvent.layerID == LAY_APPEARANCE)		{			if (myEvent.infoID == INF_VISIBLE)			{				if (myEvent.newValue.getStringValue() == "TRUE")				{										//std::cout << "ENABLE" << myEvent.objectID << std::endl;					m_calcVis.setStatus(myEvent.objectID,true);				}				else				{					//std::cout << "DISABLE" << myEvent.objectID << std::endl;					m_calcVis.setStatus(myEvent.objectID,false);				}			}				}				else if (myEvent.objectID == OBJ_COMMUNICATION && myEvent.layerID == LAY_GLOBALEVENTS && string(myEvent.newValue) == MSG_LOADED)		{			std::cout << "METKAutoFading   loaded event ... call _init" << std::endl;			_init->notify();		}	}	clearEventContainer();}
开发者ID:cguagliano,项目名称:communitymodules,代码行数:41,


示例4: getObjContainer

//!Set the value of an attribute in the ObjMgr-DB - no Notification will be sendvoid ObjMgrCommunicator::setObjAttribute(const string ObjID, const string LayerID, const string InfoID, void* value, const string omInfoType, const bool createIfNotExists, const bool persistent, const bool ignoreType){  // Get writable access to object container  bool attrCreated = false;  omObjectContainer* oc = getObjContainer();  if(oc == NULL)  {    kDebug::Debug("ObjContainer not found!",kDebug::DL_LOW);  }  else  {    if (!(*oc).exists(ObjID) && !createIfNotExists)    {      kDebug::Debug("invalidObject "+ObjID,kDebug::DL_LOW);    }    else    {      omObject& obj = (*oc)[ObjID];      omAttribute& attr = obj.getAttribute(LayerID,InfoID);      if (!obj.hasAttribute(LayerID,InfoID) && createIfNotExists)      {        attr.createDataType(omInfoType);        attrCreated = true;      }      if (obj.hasAttribute(LayerID,InfoID))      {        if (string(attr.getDataType()->getName())!=omInfoType && !ignoreType)        {          obj.removeAttribute(LayerID,InfoID);          attr.createDataType(omInfoType);          attrCreated = true;        }      }      attr.flags().markPersistent(persistent);      //Diese Sache mit den void*-Pointern zur Verallgemeinerung wird uns irgendwann mal m
C++ string2ll函数代码示例
C++ strim函数代码示例
万事OK自学网:51自学网_软件自学网_CAD自学网自学excel、自学PS、自学CAD、自学C语言、自学css3实例,是一个通过网络自主学习工作技能的自学平台,网友喜欢的软件自学网站。