请教个getline读取文件的问题

czbever czbever 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
我用getline读取dat文件的时候, 为什么一直退不出循环? 我代码是这样的:
BOOL GetIPS(std::ifstream& in, TiXmlDocument* xml_myDocument, TiXmlElement* xml_RootElement, std::tr1::unordered_set<std::string> & set)
{
std::string line = "";

while (std::getline(in, line) && !in.eof())
{
//std::cout << line << std::endl;

size_t pos = line.find("=");
if (pos == std::string::npos)
continue;

std::string sub_ips = line.substr(pos + 1, line.length() - pos - 1);
size_t begin_Pos = 0;
size_t found_Pos = 0;
size_t length = sub_ips.length();
while (found_Pos != std::string::npos)
{
found_Pos = sub_ips.find(";", begin_Pos, 1);
std::string ip = sub_ips.substr(begin_Pos, found_Pos - begin_Pos);

if(ip.compare("127.0.0.1") == 0)
continue;

std::cout << ip << std::endl;
set.insert(ip);
begin_Pos = found_Pos + 1;
found_Pos = sub_ips.find(";", begin_Pos, 1);

}


}
return TRUE;
}
...全文

相关推荐

评论 9
收藏 已收藏
分享
返回顶部
czbever
C++ 语言 65,214 成员 250,514 内容