我有一个名为Network.txt的文件,其SSID和BSSID如下所示
SSID BSSID MODE FREQ RATE SIGNAL SECURITY ACTIVE
'Bards Tale' 30:DA:9B:70:EE:F4 Infrastructure 2412 MHz 54 MB/s 47 WPA2 no
'Alaskan Pale' 70:37:73:B7:3A:53 Infrastructure 2412 MHz 54 MB/s 44 WPA2 yes
'Abita Turbodog' 9C:1E:04:4C:59:FC Infrastructure 2412 MHz 54 MB/s 7 WPA WPA2 no
'Alaskan Amber' 12:62:EB:2C:C0:06 Infrastructure 2422 MHz 54 MB/s 2 WPA WPA2 no
~
我想以安全有效的方式获得SSID和BSSID,这是我的方法,它可以正常工作但是可以改进吗?
void GetSSIDAndBSSID(const std::string &temp)
{
if (temp.find("'") != std::string::npos)
{
std::string::size_type end_pos = temp.find_last_of(":");
if (end_pos == std::string::npos)
end_pos = temp.size();
std::string FirstWord = temp.substr(1, end_pos+2);
std::cout <<"SSID="<< FirstWord.substr(0,temp.find_last_of("'")-1) << std::endl;
std::cout<<"BSSID=" << FirstWord.substr(temp.find_first_of(":")-2,temp.find_last_of(":")+2) << std::endl;
}
}
int main()
{
ifstream fin("pathTO/Network.txt");
std::string line;
while(getline(fin,line))
{
GetSSIDAndBSSID(line);
}
这段代码可以改进吗?