获取MFC中的数组位置 [英] Get position of array in MFC

查看:145
本文介绍了获取MFC中的数组位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述







是否可以获得阵列的位置?



示例:

Hi,


Is it possible to get the position of an array?

Example:

int iArray[] = {2, 3, 10, 35, 5, 87, 9, 6};
          iValue = m_iValue    // m_iValue = 5 -> from database





现在我得到了iValue,但我想在iArray中搜索这个值并得到它的位置 - 这里它将是iValue = 5所以位置必须是4 => iArray [4]。



C ++中有什么方法吗?







问候

Epanjohura



Now i got "iValue" but I want to "search" this value in "iArray" and get its position - here it would be iValue = 5 so the position must be 4 => iArray[4].

Is there any method in C++ for that?



Greetings
Epanjohura

推荐答案



i think你有一个数字数组,你想检查数组中是否存在输入的值,如果它存在,那么在哪个位置。你想通过使用c ++已经提供的一些方法来做到这一点。 (如果我错了,请更正!)



您可以使用 vector [ ^ ]而不是阵列



请参见此处 [ ^ ]关于如何使用std:distance算法来找到迭代器的索引

a类似的问题是此处有关迭代器的索引 [ ^ ]



检查如何在向量中查找值在其中 [ ^ ]

如果你还想使用数组查看此处 [ ^ ]



希望这有助于

i think you have an array of numbers and you want to check if the entered value is present in the array and if it is present then at which location. you want to do this by using some method which c++ already provides. (please correct if i am wrong !)

you can do this easily by using vector[^] instead of an array

see here[^] on how to use std:distance algorithm to find the index of an iterator
a similar question is here on index of an iterator[^]

check how to find value in a vector here[^]
if you still want to use an array look here[^]

hope this helps


您可以使用 std :: find [ ^ ](或简单地写一下简单的serach函数)。
You may use std::find[^] for that (or simply write yourself the simple serach function).


这篇关于获取MFC中的数组位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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