需要帮助将整数与字符串进行比较

时间:2019-06-23 16:26:36

标签: c++ arrays

我必须为此任务创建电话簿。对于此特定功能,我必须找到具有相同区号的人。

我将区号作为整数传递。但是,整个电话号码将作为数组的一部分保存到字符串中。我需要帮助找到遍历数组并比较两者的正确方法。

对于此示例,我尝试将传入的区号转换为字符串,然后使用find函数查看区号是否在字符串中。我也尝试过使用比较功能,但未见任何成功。

void printPersonsHavingSameAreaCodePhoneNum(addressBookType addressBook[], 
int numOfAddress, int areaCode){



cout << "List of Names who have phone number with area code: " << areaCode 
<< endl;

bool found = false;

stringstream ss;
ss << areaCode <<endl;

string areaCodeString=ss.str();

 for(int i=0;i<numOfAddress;i++){
    if(addressBook[i].getPhoneNumber().find(areaCodeString)){
        addressBook[i].print();
        found=true;
    }
 }

  if(!found){
    cout << "No Records found!" << endl;
    cout << "- - - - - - - - - - - - - - - - - -" <<  endl;
  }


}

没有错误消息发生,它只是说没有找到记录,即使我给出的数据不正确。

0 个答案:

没有答案
相关问题