小编sna*_*iii的帖子

如何使用地图C++中的值获取匹配键

我有一个结构作为值类型的地图

map<int id, struct_t*> table

struct_t
{
int prev;
int wt;
string name;
}
Run Code Online (Sandbox Code Playgroud)

仅使用prev,我需要找到相应的id.非常感谢提前!

编辑:

int key=0;
for(auto it = table.begin(); it != table.end(); ++it)
{
     if(table[(*it).first].prev == ?)
}
Run Code Online (Sandbox Code Playgroud)

这就是我的地图数据的样子:

id    prev abundance  thing
1573  -1      0       book
1864  1573    39      beds
2075  1864    41      tray
1760  2075    46      cups
Run Code Online (Sandbox Code Playgroud)

对于每个id,我需要找到NEXT匹配id.因此,对于来自prev列的1573,我需要找到匹配的'id',即1864.此外,std :: next不起作用,因为数据集可以具有匹配的id,不一定在下一个元素中.希望这有帮助!

请帮帮我!!! 我的老板已经很失望我花了这么多时间学习C++(已经有3周了!)

c++ struct stl map

8
推荐指数
3
解决办法
3万
查看次数

Python IndentationError:Xcode 上“预期有缩进块”

我在 xcode 和 vi 上遇到了这个错误。Python 表示行类 LeastModel 有一个 IndentationError: Expected an indented block。我在 Xcode 上检查了我的首选项,以使用 4 个空格作为制表符,并且在我一直使用制表符的任何地方。请帮我!

def make_model(data,model):

class LeastModel():
    """
    linear system solved using linear least squares
    This class serves as an example that fulfills the model interface needed by the ransa function.
    """
    def __init__(self,input_columns,output_columns):
        self.input_columns = input_columns
        self.output_columns = output_columns
        #self.debug = debug
Run Code Online (Sandbox Code Playgroud)

python xcode indentation

1
推荐指数
1
解决办法
2万
查看次数

为什么我的构造函数在结构中的映射不起作用?

这是我的结构,我正在尝试为此编写默认构造函数.

struct Cnode
{
typedef std::map<char, int> nextmap;
typedef std::map<char, int> prevmap;

Cnode() : nextmap(), prevmap() {} //error
Cnode(const nextmap2, const prevmap2) : nextmap(nextmap2), prevmap(prevmap2) {}

};
Run Code Online (Sandbox Code Playgroud)

请帮我理解这个错误意味着什么:

Type 'nextmap'(aka 'map<char,int>') is not a direct or virtualbase of 'Cnode'
Type 'prevmap'(aka 'map<char,int>') is not a direct or virtualbase of 'Cnode'
Run Code Online (Sandbox Code Playgroud)

c++ constructor stl map

0
推荐指数
1
解决办法
152
查看次数

标签 统计

c++ ×2

map ×2

stl ×2

constructor ×1

indentation ×1

python ×1

struct ×1

xcode ×1