sscanf

 从一个字符串中读进与指定格式相符的数据.

例子:

#define COMPRESS_PET "%d,%d,%d,%d,%d,%d,%ld,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d"

  int nID = 0;
  int nRoleID = 0;
  int nSpeciesID = 0;
  int nGrade = 0;
  int nCharacter = 0;
  int nExp = 0;
  time_t nBirthday = 0;
  int nHp = 0;
  int nGrowRate = 0;
  int nHpLearn = 0;
  int nAttackLearn = 0;
  int nDefenseLearn = 0;
  int nSuperAttackLearn = 0;
  int nSuperDefenseLearn = 0;
  int nSpeedLearn = 0;
  int nActiveSkillOne = 0;
  int nActiveSkillOneCount = 0;
  int nActiveSkillTwo = 0;
  int nActiveSkillTwoCount = 0;
  int nActiveSkillThree = 0;
  int nActiveSkillThreeCount = 0;
  int nActiveSkillFour = 0;
  int nActiveSkillFourCount = 0;
  int nPassiveSkillOne = 0;
  int nPassiveSkillTwo = 0;
  int nPassiveSkillThree = 0;
  int nPassiveSkillFour = 0;
  int nPlace = 0;
  int nMaxHp = 0;
  int nAttack = 0;
  int nDefense = 0;
  int nSuperAttack = 0;
  int nSuperDefense = 0;
  int nSpeed = 0;

sscanf((*iter).c_str(),COMPRESS_PET, &nID, &nRoleID, &nSpeciesID, &nGrade,
    &nCharacter, &nExp, &nBirthday, &nHp, &nGrowRate, &nHpLearn,
    &nAttackLearn, &nDefenseLearn, &nSuperAttackLearn, &nSuperDefenseLearn,
    &nSpeedLearn, &nActiveSkillOne, &nActiveSkillOneCount, &nActiveSkillTwo,
    &nActiveSkillTwoCount, &nActiveSkillThree, &nActiveSkillThreeCount,
    &nActiveSkillFour, &nActiveSkillFourCount, &nPassiveSkillOne,
    &nPassiveSkillTwo, &nPassiveSkillThree, &nPassiveSkillFour, &nPlace,
    &nMaxHp, &nAttack, &nDefense, &nSuperAttack, &nSuperDefense, &nSpeed);

posted @ 2011-10-14 19:03  byfei  阅读(184)  评论(0编辑  收藏  举报