C++ 在C+中运行迭代+;在满足特定条件时存储变量
我制作了一个程序,当通道值>0.1时存储通道号。 我已经定义了迭代。 在循环中,迭代在不同的通道上运行(例如:通道1、通道2等等)。 然后我调用了另一个程序来计算这个值。它将逐个计算每个通道的值。 我的任务是获取通道值>0.1的通道。我不知道如何储存那些频道号码。如果你们能帮助我,我将不胜感激。谢谢C++ 在C+中运行迭代+;在满足特定条件时存储变量,c++,visual-studio-2010,visual-c++,C++,Visual Studio 2010,Visual C++,我制作了一个程序,当通道值>0.1时存储通道号。 我已经定义了迭代。 在循环中,迭代在不同的通道上运行(例如:通道1、通道2等等)。 然后我调用了另一个程序来计算这个值。它将逐个计算每个通道的值。 我的任务是获取通道值>0.1的通道。我不知道如何储存那些频道号码。如果你们能帮助我,我将不胜感激。谢谢 list < int > GetChannels(Node* node) { list<int> Channels = GetList(node); //callin
list < int > GetChannels(Node* node)
{
list<int> Channels = GetList(node); //calling a list which I already defined.
list<int>::iterator itr;
for (itr=Channels.begin(); itr!=Channels.end(); ++itr) {
double ChannelValue = CalculateValue(node, *itr); //calling another func
if (ChannelValue > 0.1) {
listGetChannels(节点*Node)
{
list Channels=GetList(node);//调用我已经定义的列表。
列表::迭代器itr;
对于(itr=Channels.begin();itr!=Channels.end();++itr){
双通道值=CalculateValue(节点,*itr);//调用另一个函数
如果(信道值>0.1){
`能否创建另一个列表以返回值
list < int > GetChannels(Node* node) {
list<int> Channels = GetList(node); //calling a list which I already defined.
list<int> output; // Output list.
list<int>::iterator itr;
for (itr=Channels.begin(); itr!=Channels.end(); ++itr) {
double ChannelValue = CalculateValue(node, *itr); //calling another func
if (ChannelCapacityValue > 0.1) {
output.insert(*itr);
}
}
return output;
}
listGetChannels(节点*Node){
list Channels=GetList(node);//调用我已经定义的列表。
列表输出;//输出列表。
列表::迭代器itr;
对于(itr=Channels.begin();itr!=Channels.end();++itr){
双通道值=CalculateValue(节点,*itr);//调用另一个函数
如果(信道容量值>0.1){
输出。插入(*itr);
}
}
返回输出;
}
如果我得到确切的要求,您只需要通过过滤特定谓词上的现有集合来构建一个列表,该谓词是CalculateValue(node,*itr)>0.1f
这似乎是std::copy_的一项任务,如果,排序为:
list<int> channels;
list<int> filteredChannels;
...
copy_if(channels.begin(), channels.end(), back_inserter(filteredChannels),
[node] (const int& value) { return CalculateValue(node,value) > 0.1f; }
);
列出频道;
列出过滤数据通道;
...
复制if(channels.begin()、channels.end()、back_插入器(filteredChannels),
[node](const int&value){return CalculateValue(node,value)>0.1f;}
);
既然STL已经为您提供了合适的设备,为什么还要重新发明轮子呢
如果您没有访问C++11 lambda的权限,则提供一个自定义函数,例如,bool isValidChannel(const int&channel){…}但这需要绑定<代码>节点< /COD>参数。< /P>我已经编辑了代码,以便它是可读的。谢里仍然没有可读性!你错过了<代码>的正文,如果语句!@肖恩,我想问题是关于什么在那里。我的问题是什么语言?C++还是C?是的,因为这是我的问题。.如果ChannelValue>0.1,我不知道如何存储频道是的,本。这是我的问题。非常感谢本:)非常感谢杰克。你的回答真的很有帮助:)