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


C++ StringFormat函数代码示例

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


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

示例1: PipeWriteData

int PipeWriteData(const char *base_cmd, const char *args, const char *data)
{
    assert(base_cmd);
    assert(args);

    char *command = StringFormat("%s %s", base_cmd, args);
    IOData io = cf_popen_full_duplex(command, false, true);
    free(command);

    if (io.write_fd == -1 || io.read_fd == -1)
    {
        Log(LOG_LEVEL_VERBOSE, "Error occurred while opening pipes for "
            "communication with application '%s'.", base_cmd);
        return -1;
    }

    Log(LOG_LEVEL_DEBUG, "Opened fds %d and %d for command '%s'.",
        io.read_fd, io.write_fd, args);

    int res = 0;
    if (PipeWrite(&io, data) != strlen(data))
    {
        Log(LOG_LEVEL_VERBOSE,
            "Was not able to send whole data to application '%s'.",
            base_cmd);
        res = -1;
    }

    /* If script returns non 0 status */
    int close = cf_pclose_full_duplex(&io);
    if (close != EXIT_SUCCESS)
    {
        Log(LOG_LEVEL_VERBOSE,
            "Application '%s' returned with non zero return code: %d",
            base_cmd, close);
        res = -1;
    }
    return res;
}
开发者ID:cfengine,项目名称:core,代码行数:39,代码来源:pipes.c

示例2: main

task main () {
  string _tmp;

  displayCenteredTextLine(0, "HiTechnic");
  displayCenteredBigTextLine(1, "Color V2");
  displayCenteredTextLine(3, "Test 1");
  displayCenteredTextLine(5, "Connect sensor");
  displayCenteredTextLine(6, "to S1");
  sleep(2000);

  // Create struct to hold sensor data
  tHTCS2 colorSensor;

  // Initialise and configure struct and port
  initSensor(&colorSensor, S1);

  eraseDisplay();
  while (true)
  {
    // Read the currently detected colour and RGB/HSV data from the sensor
    if (!readSensor(&colorSensor)) {
      displayTextLine(4, "ERROR!!");
      sleep(2000);
      stopAllTasks();
    }

    displayCenteredTextLine(0, "Color: %d", colorSensor.color);
    displayCenteredBigTextLine(1, "R  G  B");

    eraseRect(0,10, 99, 41);
    fillRect( 0, 10, 30, 10 + (colorSensor.red+1)/8);
    fillRect(35, 10, 65, 10 + (colorSensor.green+1)/8);
    fillRect(70, 10, 99, 10 + (colorSensor.blue+1)/8);
    StringFormat(_tmp, " %3d   %3d", colorSensor.red, colorSensor.green);
    displayTextLine(7, "%s   %3d", _tmp, colorSensor.blue);

    sleep(100);
  }
}
开发者ID:botbenchtutorial,项目名称:robotcdriversuite,代码行数:39,代码来源:hitechnic-colour-v2-test1.c

示例3: StringFormat

int32 ZoneDatabase::GetDoorsDBCountPlusOne(const char *zone_name, int16 version) {

    uint32 oMaxID = 0;

    std::string query = StringFormat("SELECT MAX(doorid) FROM doors "
                                     "WHERE zone = '%s' AND (version = %u OR version = -1)",
                                     zone_name, version);
    auto results = QueryDatabase(query);
    if (!results.Success()) {
        return -1;
    }

    if (results.RowCount() != 1)
        return -1;

    auto row = results.begin();

    if (!row[0])
        return 0;

    return atoi(row[0]) + 1;
}
开发者ID:ngdeao,项目名称:Server-1,代码行数:22,代码来源:doors.cpp

示例4: switch

void RuleManager::_SaveRule(Database *db, RuleType type, uint16 index) {
	char vstr[100];

	switch(type) {
	case IntRule:
		sprintf(vstr, "%d", m_RuleIntValues[index]);
		break;
	case RealRule:
		sprintf(vstr, "%.13f", m_RuleRealValues[index]);
		break;
	case BoolRule:
		sprintf(vstr, "%s", m_RuleBoolValues[index]?"true":"false");
		break;
	}

	std::string query = StringFormat("REPLACE INTO rule_values "
                                    "(ruleset_id, rule_name, rule_value) "
                                    " VALUES(%d, '%s', '%s')",
                                    m_activeRuleset, _GetRuleName(type, index), vstr);
    auto results = db->QueryDatabase(query);

}
开发者ID:jcon321,项目名称:Server,代码行数:22,代码来源:rulesys.cpp

示例5: main

task main () {
  int _x_axis = 0;
  int _y_axis = 0;
  int _z_axis = 0;

  string _tmp;

  nxtDisplayCenteredTextLine(0, "HiTechnic");
  nxtDisplayCenteredBigTextLine(1, "Accel");
  nxtDisplayCenteredTextLine(3, "Test 1");
  nxtDisplayCenteredTextLine(5, "Connect sensor");
  nxtDisplayCenteredTextLine(6, "to S1");
  wait1Msec(2000);

  PlaySound(soundBeepBeep);
  while(bSoundActive) EndTimeSlice();

  while (true) {
    eraseDisplay();

    // Read all of the axes at once
    if (!HTACreadAllAxes(HTAC, _x_axis, _y_axis, _z_axis)) {
      nxtDisplayTextLine(4, "ERROR!!");
      wait1Msec(2000);
      StopAllTasks();
    }

    nxtDisplayTextLine(0,"HTAC Test 1");

    // We can't provide more than 2 parameters to nxtDisplayTextLine(),
    // so we'll do in two steps using StringFormat()
    nxtDisplayTextLine(2, "   X    Y    Z");
    StringFormat(_tmp, "%4d %4d", _x_axis, _y_axis);
    nxtDisplayTextLine(3, "%s %4d", _tmp, _z_axis);

    wait1Msec(100);
  }
}
开发者ID:DaltonFTC,项目名称:Robot1Code,代码行数:38,代码来源:HTAC-test1.c

示例6: VOODOO_METHODDEF

        VOODOO_METHODDEF(VSParameterDX9::SetTexture)(_In_ ITexture * pVal)
        {
            VOODOO_DEBUG_FUNCLOG(m_Core->GetLogger());

            if (m_Desc.Type < VSPT_Texture || m_Desc.Type > VSPT_TextureCube) return VSFERR_INVALIDCALL;

            m_Texture = pVal;

            ParameterList::iterator child = m_Attached.begin();
            while (child != m_Attached.end())
            {
                (*child)->SetTexture(pVal);
            }

            if (m_Effect && m_Handle)
            {
                Variant propVar = CreateVariant();
                if (FAILED(pVal->GetProperty(PropIds::D3D9Texture, &propVar)))
                {
                    m_Core->GetLogger()->LogMessage(VSLog_PlugError, VOODOO_D3D9_NAME, StringFormat("Unable to get hardware texture from texture %1%.") << pVal);
                    return VSFERR_INVALIDPARAMS;
                }

                LPDIRECT3DTEXTURE9 pDXTexture = reinterpret_cast<LPDIRECT3DTEXTURE9>(propVar.VPVoid);

                HRESULT hr = m_Effect->m_Handle->SetTexture(m_Handle, pDXTexture);

                if (FAILED(hr))
                {
                    m_Core->GetLogger()->LogMessage(VSLog_PlugError, VOODOO_D3D9_NAME, StringFormat("Unable to bind texture %1% to parameter %2%.") << pVal << this);
                    return VSFERR_INVALIDCALL;
                }

                m_Core->GetLogger()->LogMessage(VSLog_PlugDebug, VOODOO_D3D9_NAME, StringFormat("Bound texture %1% to parameter %2%.") << pVal << this);
            }

            return VSF_OK;
        }
开发者ID:btblog,项目名称:VoodooShader,代码行数:38,代码来源:VSParameterDX9.cpp

示例7: return

bool BaseGuildManager::GetEntireGuild(uint32 guild_id, std::vector<CharGuildInfo *> &members) {
	members.clear();

	if(m_db == nullptr)
		return(false);

	//load up the rank info for each guild.
	std::string query = StringFormat(GuildMemberBaseQuery " WHERE g.guild_id=%d", guild_id);
	auto results = m_db->QueryDatabase(query);
	if (!results.Success()) {
		return false;
	}

	for (auto row = results.begin(); row != results.end(); ++row) {
		auto ci = new CharGuildInfo;
		ProcessGuildMember(row, *ci);
		members.push_back(ci);
	}

	Log(Logs::Detail, Logs::Guilds, "Retreived entire guild member list for guild %d from the database", guild_id);

	return true;
}
开发者ID:EQEmu,项目名称:Server,代码行数:23,代码来源:guild_base.cpp

示例8: RemoveApostrophes

int Database::FindCharacter(const char *characterName) {

	char *safeCharName = RemoveApostrophes(characterName);
    std::string query = StringFormat("SELECT `id` FROM `character_` WHERE `name`='%s' LIMIT 1", safeCharName);
    auto results = QueryDatabase(query);
	if (!results.Success()) {
		_log(UCS__ERROR, "FindCharacter failed. %s %s", query.c_str(), results.ErrorMessage().c_str());
		safe_delete(safeCharName);
		return -1;
	}
    safe_delete(safeCharName);

	if (results.RowCount() != 1) {
		_log(UCS__ERROR, "Bad result from FindCharacter query for character %s", characterName);
		return -1;
	}

	auto row = results.begin();

	int characterID = atoi(row[0]);

	return characterID;
}
开发者ID:quido,项目名称:Server,代码行数:23,代码来源:database.cpp

示例9: StringFormat

void Database::LogPlayerAARateHourly(QSPlayerAARateHourly_Struct* QS, uint32 items)
{
	if (items == 0)
	{
		return;
	}

	std::string query = StringFormat(
		"INSERT INTO `qs_player_aa_rate_hourly` (char_id, aa_count, hour_time) "
			"VALUES "
			"(%i, %i, UNIX_TIMESTAMP() - MOD(UNIX_TIMESTAMP(), 3600)) "
			"ON DUPLICATE KEY UPDATE "
			"`aa_count` = `aa_count` + %i",
			QS->charid,
			QS->add_points,
			QS->add_points);

	auto results = QueryDatabase(query);
	if (!results.Success())
	{
		Log.Out(Logs::Detail, Logs::QS_Server, "Failed AA Rate Log Record Insert: %s\n%s", results.ErrorMessage().c_str(), query.c_str());
	}
}
开发者ID:jcon321,项目名称:Server,代码行数:23,代码来源:database.cpp

示例10: StringFormat

bool EQLConfig::SetDynamicCount(int count) {

	char namebuf[128];
	database.DoEscapeString(namebuf, m_name.c_str(), m_name.length()&0x3F);	//limit len to 64
	namebuf[127] = '\0';

    std::string query = StringFormat("UPDATE launcher SET dynamics=%d WHERE name='%s'", count, namebuf);
    auto results = database.QueryDatabase(query);
	if (!results.Success()) {
		return false;
	}

	//update in-memory version.
	m_dynamics = count;

	//if the launcher is connected, update it.
	LauncherLink *ll = launcher_list.Get(m_name.c_str());
	if(ll != nullptr) {
		ll->BootDynamics(count);
	}

	return false;
}
开发者ID:9thsector,项目名称:Server,代码行数:23,代码来源:eql_config.cpp

示例11: StringFormat

bool Database::Create_ItemMove_Table()
{
	Log.Out(Logs::Detail, Logs::QS_Server, "Attempting to create item move table.");
	std::string query = StringFormat(
		"CREATE TABLE `qs_player_item_move_log` ( "
		"`char_id` int(11) DEFAULT '0', "
		"`from_slot` mediumint(7) DEFAULT '0', "
		"`to_slot` mediumint(7) DEFAULT '0', "
		"`item_id` int(11) DEFAULT '0', "
		"`charges` mediumint(7) DEFAULT '0', "
		"`stack_size` mediumint(7) DEFAULT '0', "
		"`char_items` mediumint(7) DEFAULT '0', "
		"`postaction` tinyint(1) DEFAULT '0', "
		"`time` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP "
		") ENGINE = InnoDB DEFAULT CHARSET = utf8;");
	auto results = QueryDatabase(query);
	if (!results.Success())
	{
		Log.Out(Logs::General, Logs::QS_Server, "Error creating qs_player_item_move_log. \n%s", query.c_str());
		return false;
	}
	return true;
}
开发者ID:jcon321,项目名称:Server,代码行数:23,代码来源:dbupdate.cpp

示例12: Log

int16 SpawnConditionManager::GetCondition(const char *zone_short, uint32 instance_id, uint16 condition_id) {
	if(!strcasecmp(zone_short, zone->GetShortName()) && instance_id == zone->GetInstanceID())
	{
		//this is a local spawn condition
		std::map<uint16, SpawnCondition>::iterator condi;
		condi = spawn_conditions.find(condition_id);
		if(condi == spawn_conditions.end())
		{
			Log(Logs::Detail, Logs::Spawns, "Unable to find local condition %d in Get request.", condition_id);
			return(0);	//unable to find the spawn condition
		}

		SpawnCondition &cond = condi->second;
		return cond.value;
	}

	//this is a remote spawn condition, grab it from the DB
    //load spawn conditions
    std::string query = StringFormat("SELECT value FROM spawn_condition_values "
                                    "WHERE zone = '%s' AND instance_id = %u AND id = %d",
                                    zone_short, instance_id, condition_id);
    auto results = database.QueryDatabase(query);
    if (!results.Success()) {
        Log(Logs::Detail, Logs::Spawns, "Unable to query remote condition %d from zone %s in Get request.", condition_id, zone_short);
		return 0;	//dunno a better thing to do...
    }

    if (results.RowCount() == 0) {
        Log(Logs::Detail, Logs::Spawns, "Unable to load remote condition %d from zone %s in Get request.", condition_id, zone_short);
		return 0;	//dunno a better thing to do...
    }

    auto row = results.begin();

    return atoi(row[0]);
}
开发者ID:N0ctrnl,项目名称:VAServer,代码行数:36,代码来源:spawn2.cpp

示例13: GenericAgentConfigSetInputFile

void GenericAgentConfigSetInputFile(GenericAgentConfig *config, const char *workdir, const char *input_file)
{
    free(config->original_input_file);
    free(config->input_file);
    free(config->input_dir);

    config->original_input_file = xstrdup(input_file);

    if (workdir && FilePathGetType(input_file) == FILE_PATH_TYPE_NON_ANCHORED)
    {
        config->input_file = StringFormat("%s%cinputs%c%s", workdir, FILE_SEPARATOR, FILE_SEPARATOR, input_file);
    }
    else
    {
        config->input_file = xstrdup(input_file);
    }

    config->input_dir = xstrdup(config->input_file);
    if (!ChopLastNode(config->input_dir))
    {
        free(config->input_dir);
        config->input_dir = xstrdup(".");
    }
}
开发者ID:nperron,项目名称:core,代码行数:24,代码来源:generic_agent.c

示例14: strlen

// Add new Zone Object (theoretically only called for items dropped to ground)
uint32 ZoneDatabase::AddObject(uint32 type, uint32 icon, const Object_Struct& object, const ItemInst* inst)
{
	uint32 database_id = 0;
	uint32 item_id = 0;
	int16 charges = 0;

	if (inst && inst->GetItem()) {
		item_id = inst->GetItem()->ID;
		charges = inst->GetCharges();
	}

	// SQL Escape object_name
	uint32 len = strlen(object.object_name) * 2 + 1;
	char* object_name = new char[len];
	DoEscapeString(object_name, object.object_name, strlen(object.object_name));

    // Save new record for object
	std::string query = StringFormat("INSERT INTO object "
                                    "(zoneid, xpos, ypos, zpos, heading, "
                                    "itemid, charges, objectname, type, icon) "
                                    "values (%i, %f, %f, %f, %f, %i, %i, '%s', %i, %i)",
                                    object.zone_id, object.x, object.y, object.z, object.heading,
                                    item_id, charges, object_name, type, icon);
    safe_delete_array(object_name);
	auto results = QueryDatabase(query);
	if (!results.Success()) {
		LogFile->write(EQEMuLog::Error, "Unable to insert object: %s", results.ErrorMessage().c_str());
		return 0;
	}

    // Save container contents, if container
    if (inst && inst->IsType(ItemClassContainer))
        SaveWorldContainer(object.zone_id, database_id, inst);

	return database_id;
}
开发者ID:quido,项目名称:Server,代码行数:37,代码来源:object.cpp

示例15: StringFormat

void Raid::RemoveMember(const char *characterName)
{
	std::string query = StringFormat("DELETE FROM raid_members where name='%s'", characterName);
	auto results = database.QueryDatabase(query);

	Client *client = entity_list.GetClientByName(characterName);
	disbandCheck = true;
	SendRaidRemoveAll(characterName);
	SendRaidDisband(client);
	LearnMembers();
	VerifyRaid();

	if(client)
		client->SetRaidGrouped(false);

	ServerPacket *pack = new ServerPacket(ServerOP_RaidRemove, sizeof(ServerRaidGeneralAction_Struct));
	ServerRaidGeneralAction_Struct *rga = (ServerRaidGeneralAction_Struct*)pack->pBuffer;
	rga->rid = GetID();
	rga->instance_id = zone->GetInstanceID();
	strn0cpy(rga->playername, characterName, 64);
	rga->zoneid = zone->GetZoneID();
	worldserver.SendPacket(pack);
	safe_delete(pack);
}
开发者ID:surlyone,项目名称:Server,代码行数:24,代码来源:raids.cpp


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