将列表与一个值进行比较 [英] Comparing a List Against One Value

查看:107
本文介绍了将列表与一个值进行比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在获取与当前URL关联的IP列表.我想将此列表与单个IP地址进行比较.我可以将一个IP与另一个IP进行比较.然而;如何将一个IP列表与一个IP进行比较?谢谢.

I am getting a list of IP associated with the current URL. I want to compare this list to a single IP address. I can compare one IP to another. However; how does one compare a list of IP''s against one IP? Thank you.

if (Newlength > 0) 
  { 
  sHost.resize(Newlength); 
  WideCharToMultiByte (CP_ACP, WC_COMPOSITECHECK, wsHost.c_str(), wsHost.length(), &sHost[0], Newlength, NULL, NULL);
  } 
  HOSTENT *pHostEnt2 = gethostbyname(sHost.c_str()); 
  if (!pHostEnt2) 
	{ 
	printf("\n   Unknown Website IP"); 
	} 
	else 
	{ 
	for 
	(char **addr = pHostEnt2->h_addr_list; *addr != NULL; ++addr) 
        { 
	printf("\n   Website IP: %s  \n", inet_ntoa(* (struct in_addr *) *addr)); 
	} 
	} 
	}

推荐答案

正如SA所说,您确实没有表现出问题".您发布的代码仅显示打印出一些内容,没有进行比较或要与之进行比较.

嘿,我有个主意.如果您已经有一个循环来打印出所有地址,那么为什么不尝试循环将每个地址与您要查找的内容进行比较,而不是打印出来.

没有将此与事物列表比较"命令或函数,您必须自己编写.

或者,您可以研究(使用Google)网上一些可用的查找"或查找"功能.当然,您必须按照自己确定的任何功能想要的方式来排列列表.

我们非常乐意提供帮助,但是如果您不给出明确的问题说明或将相关代码发布到所陈述的问题上,或者提供证据证明您自己尝试或研究了某些内容,则您不太可能获得帮助任何帮助.

如果不是您执行此操作的第20或30次,我不会在此消息中如此尖刻.
As SA said, you really haven''t shown a "problem". The code you posted only shows printing out some stuff, not comparing or what you want to compare to.

Hey, I have an idea. If you already have a loop to print out all the addresses, why not try a loop to compare each to what you are looking for instead of printing them.

There is no "compare this to a list of things" command or function, you have to write this yourself.

Or, you could research (using Google) some "Find" or "Lookup" functions available out there on the net. Of course, you''d have to arrange your list the way any function you identify would want it.

We''d really love to help but if you won''t give clear problem statement or post relevant code to the problem you stated or give evidence that you either tried something yourself or researched it yourself, you''re not likely to get any help.

I wouldn''t be so strident in this message if it wasn''t the 20th or 30th time you''ve done this.


这篇关于将列表与一个值进行比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆