zay999abc
霍天青
2015-05-25 06:09
采纳率: 63%
浏览 2.3k

一个简单的C++程序,求助。

bool func(const string &);
int main(void)
{
vector vec{ "strings", "helloworld", "zay", "uah", "kakaka" };
auto it = partition(vec.cbegin(), vec.cend(), func);
auto begin = vec.begin();
while (begin != it)
{
cout << *begin << endl;
++begin;
}
return 0;
}
bool func(const string& str)
{
if (str.size() >= 5)
return true;
else
return false;
}
出现错误:没有找到接受……类型的左操作数的运算符(或没有可接受的转换)。

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

16条回答 默认 最新

  • tangsha928
    疯狂的糖豆 2015-05-25 08:55
    已采纳

    cbegin()返回指向范围内第一个元素的 const 迭代器,可以使用此成员函数替代 begin() 成员函数
    partition(vec.cbegin(), vec.cend(), func);这行代码出错了
    把cbegin()改为begin(), cend() 改为end()就ok了

    点赞 评论
  • nswcfd
    nswcfd 2015-05-25 07:01

    这种初始化vector的方式是c++ 2011的语法?

    点赞 评论
  • a1193561652
    纵横车 2015-05-25 07:16

    创建vector不是vector vec这样的语法码?

    点赞 评论
  • oyljerry
    oyljerry 2015-05-25 07:51

    具体哪一行出错。是不是++begin; 不能自增?

    点赞 评论
  • pbymw8iwm
    高司机 2015-05-25 08:50

    这个是C11标准的初始化方式好像,it 最好加一下迭代器类型吧

    点赞 评论
  • u012377333
    一枪尽骚丶魂 2015-05-25 10:01

    是编译的时候的语法错误么?提示信息里面没有定位的信息么?

    点赞 评论
  • u012271952
    浪前青山 2015-05-25 12:23

    auto it = partition(vec.cbegin(), vec.cend(), func);
    auto begin = vec.begin();
    ???这是什么语法?缺少数据类型啊

    点赞 评论
  • xy707707
    KrisRoofe 2015-05-27 09:21

    cbegin()返回指向范围内第一个元素的 const 迭代器,可以使用此成员函数替代 begin() 成员函数
    partition(vec.cbegin(), vec.cend(), func);这行代码出错了
    把cbegin()改为begin(), cend() 改为end()就ok了

    点赞 评论
  • pbymw8iwm
    高司机 2017-06-20 07:30

    /*
    C->S 升级(强化)灵器
    {
    "module":"updateanima",

    "session":"1111111111111",//sessionid用来校验的
    "userid":"1",//玩家id
    "targetid":1 灵器id
    "material"=>array("ma001"=>1,"mc002"=>2);//选择的升级材料
    }

    S->C
    {
    "ts":"132323232323"//服务器时间戳

    "errcode":"0"
    "errmsg":""
    。。。
    }*/
    public function updateAnima($post_array)
    {
    if(isset($post_array['session']) && isset($post_array['userid'])&& isset($post_array['index']))
    {
    //检查设备登录的数据库信息
    $this->load->model("UserDB_model","Player");
    $cli_session = $post_array['session'];//签名实际上就是服务器的session
    $accountId = $post_array['userid'];//玩家的session其实就是玩家的id

    $ret = $this->Player->checkUserAccount($accountId,$cli_session);
    if($ret == false){
    $return_Data = array("ts"=> time(), "errcode" => -1, "errmsg" => "Logout");

    echo json_encode($return_Data); //根据实际情况返回json
    }else{ //找到这个玩家,那么处理下线的时间等等
    $return_Data = $this->Player->updateAnima($accountId,$post_array["targetid"],$post_array["material"]);
    echo json_encode($return_Data);
    }

    }else{
    $return_Data = array("ts"=> time(), "errcode" => -1, "errmsg" => "Parameter error");

    echo json_encode($return_Data); //根据实际情况返回json
    }
    }

    点赞 评论
  • pbymw8iwm
    高司机 2017-06-20 07:36

    /*
    C->S 进阶灵器
    {
    "module":"advanceanima",

    "session":"1111111111111",//sessionid用来校验的
    "userid":"1",//玩家id
    "targetid":1 灵器id
    "material"=>array("ma001"=>1,"mc002"=>2);//选择的进阶材料
    }

    S->C
    {
    "ts":"132323232323"//服务器时间戳

    "errcode":"0"
    "errmsg":""
    。。。
    }*/
    public function advanceAnima($post_array)
    {
    if(isset($post_array['session']) && isset($post_array['userid'])&& isset($post_array['index']))
    {
    //检查设备登录的数据库信息
    $this->load->model("UserDB_model","Player");
    $cli_session = $post_array['session'];//签名实际上就是服务器的session
    $accountId = $post_array['userid'];//玩家的session其实就是玩家的id

    $ret = $this->Player->checkUserAccount($accountId,$cli_session);
    if($ret == false){
    $return_Data = array("ts"=> time(), "errcode" => -1, "errmsg" => "Logout");

    echo json_encode($return_Data); //根据实际情况返回json
    }else{ //找到这个玩家,那么处理下线的时间等等
    $return_Data = $this->Player->advanceAnima($accountId,$post_array["targetid"],$post_array["material"]);
    echo json_encode($return_Data);
    }

    }else{
    $return_Data = array("ts"=> time(), "errcode" => -1, "errmsg" => "Parameter error");

    echo json_encode($return_Data); //根据实际情况返回json
    }
    }

    点赞 评论
  • pbymw8iwm
    高司机 2017-06-20 07:36

    /*
    C->S 分解灵器
    {
    "module":"resolveanima",

    "session":"1111111111111",//sessionid用来校验的
    "userid":"1",//玩家id
    "targetid":1 灵器id
    }

    S->C
    {
    "ts":"132323232323"//服务器时间戳

    "errcode":"0"
    "errmsg":""
    。。。
    }*/
    public function resolveAnima($post_array)
    {
    if(isset($post_array['session']) && isset($post_array['userid'])&& isset($post_array['index']))
    {
    //检查设备登录的数据库信息
    $this->load->model("UserDB_model","Player");
    $cli_session = $post_array['session'];//签名实际上就是服务器的session
    $accountId = $post_array['userid'];//玩家的session其实就是玩家的id

    $ret = $this->Player->checkUserAccount($accountId,$cli_session);
    if($ret == false){
    $return_Data = array("ts"=> time(), "errcode" => -1, "errmsg" => "Logout");

    echo json_encode($return_Data); //根据实际情况返回json
    }else{ //找到这个玩家,那么处理下线的时间等等
    $return_Data = $this->Player->resolveAnima($accountId,$post_array["targetid"]);
    echo json_encode($return_Data);
    }

    }else{
    $return_Data = array("ts"=> time(), "errcode" => -1, "errmsg" => "Parameter error");

    echo json_encode($return_Data); //根据实际情况返回json
    }
    }

    点赞 评论
  • pbymw8iwm
    高司机 2017-06-21 09:59

    roleinfo => array(
    "roleid_1" => array("grid"=>array(1=>"12311",2=>""),"anima"=>"123123123213213", "pet"=>"pc_012", "level"=>1,"quality"=>12, "exp"=>120);
    "roleid_2" => array("grid"=>array(1=>"12311"),"anima"=>"", "pet"=>"pc_012", "level"=>12,"quality"=>12);//没有解锁两个装备栏,没有装备任何灵器
    );

    点赞 评论
  • pbymw8iwm
    高司机 2017-06-21 10:06
    public function advanceAnima($accountId,$targetId, $lingqiarr)
    {
        //找到自己的装备信息
        $equipInfo = $this->Player->getUserBlobInfo(array("userequip"),$accountId);
        if(count($equipInfo["userequip"]) == 0)
        {
            $return_Data = array( "ts"=> time(), "errcode" => -2, "errmsg" => "You have no this equipment"); 
            return ($return_Data);  
        }
    
        foreach($equipInfo["userequip"]["lingqi"] as $equipKey => $equipValue)
        {
            if($equipKey == $targetId)
            {
                $level_array = array(20,40,60,80);//如果达到这些等级只能通过进阶了
                $old_level = $equipValue['level'];//升级之前的等级
                if(!isset($level_array[$old_level]))
                {
                    $return_Data = array( "ts"=> time(), "errcode" => -4, "errmsg" => "advance anima failed"); 
                    return ($return_Data);  
                } 
                if(!(isset($equipInfo["userequip"]["lingqi"][$equipKey]['needadvance']) && $equipInfo["userequip"]["lingqi"][$equipKey]['needadvance'] == true))//如果是可以进阶了需要加一个锁
                {
                    $return_Data = array( "ts"=> time(), "errcode" => -7, "errmsg" => "you cannot advance anima twice"); 
                    return ($return_Data); 
                }
                $advanceItemArray = array();
                $EqupData = xmlConfig::LoadXmlData("material.xml"); 
                foreach($EqupData["anima_anima_qualitys"]["anima_quality"] as $sheet_key => $sheet_value){
                    foreach($sheet_value as $item_key => $value){
                        if($old_level == $value['lv'])
                        {
                            $advanceItemArray = $value;
                            break;
                        }
                    }
                } 
    
    点赞 评论
  • pbymw8iwm
    高司机 2017-06-21 10:07

    if(count($advanceItemArray) > 0){
    //qulity cost1 20级灵器2个 cost2 消耗的材料id cost
    $cost_res = xmlConfig::getReward($itemArray['cost']);
    if(count($lingqiarr) != $itemArray['cost_anima_number'])//数目不够
    {
    $return_Data = array("ts"=> time(), "errcode" => -5, "errmsg" => "You have not enough resources");
    return ($return_Data);
    }
    foreach($lingqiarr as $lingqiarr_key=>$lingqiarr_value)
    {
    if(!isset($equipInfo["userequip"]["lingqi"][$lingqiarr_value])//检查玩家有没有灵器
    {
    $return_Data = array("ts"=> time(), "errcode" => -6, "errmsg" => "You have not enough resources");
    return ($return_Data);
    }else{
    //检查消耗灵器的等级够不够
    if($equipInfo["userequip"]["lingqi"][$lingqiarr_value]['level'] != $itemArray['cost_anima_lv'])
    {
    $return_Data = array("ts"=> time(), "errcode" => -7, "errmsg" => "You have not enough resources");
    return ($return_Data);
    }
    }
    }
    if($this->CheckPlayerRes($cost_res,$accountId) == false){
    $return_Data = array("ts"=> time(), "errcode" => -1, "errmsg" => "You have not enough resources");
    return ($return_Data);
    }
    $new_cost = array();
    foreach($cost_res as $key => $value)
    {
    $new_cost[$key] = 0 - $value;
    }
    //扣除资源 ,等待完善,因为进阶是不是等级也要提升
    $this->addItemToPlayer($new_cost,$accountId);
    //扣除消耗的灵器
    foreach($lingqiarr as $lingqiarr_key=>$lingqiarr_value)
    {
    unset($equipInfo["userequip"]["lingqi"][$lingqiarr_value]);
    }
    $equipInfo["userequip"]["lingqi"][$equipKey]["quality"] = $advanceItemArray['quality'];
    $equipInfo["userequip"]["lingqi"][$equipKey]['needadvance'] = false;
    //$equipInfo["userequip"]["lingqi"][$equipKey]['level'] = $old_level;
    $this->updateUserBlobInfo(array("userequip"=>$equipInfo["userequip"]),$accountId);
    $return_Data = array( "ts"=> time(), "errcode" => 0, "errmsg" => "", "data" => array("status"=>1, "level"=>$equipInfo["userequip"]["lingqi"][$equipKey]));
    return ($return_Data);
    }else{
    $return_Data = array( "ts"=> time(), "errcode" => -5, "errmsg" => "advance anima failed");
    return ($return_Data);

    }

    }
    }
    $return_Data = array( "ts"=> time(), "errcode" => -3, "errmsg" => "You have no this equipment");
    return ($return_Data);

    }

    点赞 评论
  • pbymw8iwm
    高司机 2017-06-21 10:08

    foreach($EqupData["anima_enhances"]["enhance"] as $sheet_key => $sheet_value){
    foreach($sheet_value as $item_key => $value){
    if($value['id'] == $old_level + 1)
    {

    if($old_materialGrouth >= $value['grouth'])
    {
    $old_materialGrouth -= $value['grouth'];
    $old_level += 1;
    $cost_res = xmlConfig::getReward($itemArray['cost']);
    foreach($cost_res as $cost_key => $cost_value)
    {
    if(isset($cost_gold[$cost_key])){
    $cost_gold[$cost_key] += $cost_value;
    }else{
    $cost_gold[$cost_key] = $cost_value;
    }
    }
    $findFlag = true;
    if(isset($level_array[$old_level])
    {
    break;
    }
    }else{
    break;
    }
    }
    }
    }
    if($findFlag)
    {

    $cost_res = $cost_gold;
    foreach($material as $key => $value)
    {
    $cost_res[$key] = $value;
    }

                    if($this->CheckPlayerRes($cost_res,$accountId) == false){
                        $return_Data = array("ts"=> time(), "errcode" => -1, "errmsg" => "You have not enough resources"); 
                        return ($return_Data); 
                    }
                    $new_cost = array();
                    foreach($cost_res as $key => $value)
                    {
                        $new_cost[$key] = 0 - $value;
                    }
                    //扣除资源 
                    $this->addItemToPlayer($new_cost,$accountId);
                    $equipInfo["userequip"]["lingqi"][$equipKey]["grouth"] = $old_materialGrouth;//更新下当前灵器的成长值                    
                    $equipInfo["userequip"]["lingqi"][$equipKey]['level']  = $old_level;
                    if(isset($level_array[$old_level])//如果是可以进阶了需要加一个锁
                    {
                        $equipInfo["userequip"]["lingqi"][$equipKey]['needadvance'] = true;
                    }
                    $this->updateUserBlobInfo(array("userequip"=>$equipInfo["userequip"]),$accountId); 
                    $return_Data = array( "ts"=> time(), "errcode" => 0, "errmsg" => "", "data" => array("status"=>1, "level"=>$equipInfo["userequip"]["lingqi"][$equipKey])); 
                    return ($return_Data); 
                }else{  
                    $return_Data = array("ts"=> time(), "errcode" => -4, "errmsg" => "You have not enough materials"); 
                    return ($return_Data); 
                }
                break;
            }
        }
        $return_Data = array( "ts"=> time(), "errcode" => -3, "errmsg" => "You have no this equipment"); 
        return ($return_Data);  
    }
    
    点赞 评论
  • pbymw8iwm
    高司机 2017-06-21 10:09
     /*
    C->S    背包扩展
    

    {
    "module":"enlargepackage",

    "session":"1111111111111",//sessionid用来校验的
    "userid":"1",//玩家id
    }

    S->C
    {
    "ts":"132323232323"//服务器时间戳

    "errcode":"0"
    "errmsg":""
    。。。
    }*/
    public function enlargePackage($post_array)
    {
    if(isset($post_array['session']) && isset($post_array['userid']))
    {
    //检查设备登录的数据库信息
    $this->load->model("UserDB_model","Player");
    $cli_session = $post_array['session'];//签名实际上就是服务器的session
    $accountId = $post_array['userid'];//玩家的session其实就是玩家的id

    $ret = $this->Player->checkUserAccount($accountId,$cli_session);
    if($ret == false){
    $return_Data = array("ts"=> time(), "errcode" => -1, "errmsg" => "Logout");

    echo json_encode($return_Data); //根据实际情况返回json
    }else{ //找到这个玩家,那么处理下线的时间等等
    $return_Data = $this->Player->enlargePackage($accountId);
    echo json_encode($return_Data);
    }

    }else{
    $return_Data = array("ts"=> time(), "errcode" => -1, "errmsg" => "Parameter error");

    echo json_encode($return_Data); //根据实际情况返回json
    }
    }

    点赞 评论

相关推荐