小编Rak*_*r N的帖子

在 C++ 中打印 std::unordered_multimap 中特定键的多个值

我正在尝试打印与 C++ 中的 unordered_multiset 中的特定键关联的所有值,但不幸的是,当我运行以下代码时,我在 Visual Studio 和在线编译器http://cpp.sh/中得到两个不同的输出。Visual Studio 仅提供“红色”作为输出 cpp.sh 仅提供“绿色”作为输出

#include <iostream>
#include <string>
#include <unordered_map>

int main()
{
    std::unordered_map<std::string, std::string> myumm = {
    { "apple","red" },
    { "apple","green" },
    { "orange","orange" },
    { "strawberry","red" }
    };

    std::cout << "myumm contains:";
    for (auto it = myumm.begin(); it != myumm.end(); ++it)
       std::cout << " " << it->first << ":" << it->second;
    std::cout << std::endl;

    std::cout << "myumm's buckets contain:\n";
    for (unsigned i = 0; i < myumm.bucket_count(); …
Run Code Online (Sandbox Code Playgroud)

c++ stl unordered-multimap

5
推荐指数
1
解决办法
1430
查看次数

C/C++:"for"宏来跟踪运行多次迭代的循环

我尝试使用下面的代码来跟踪使用新变量的各个循环的迭代ForloopCountM.该代码适用于循环内的循环和循环循环.但是Macro在以下两种情况下都失败了,我需要帮助如何解决这个问题并跟踪迭代次数.

void    forloopTrace(int ForloopCount)
{
    if( ForloopCount==50)
    printf("Invalid \n");
}

#define CONCAT_IMPL( x, y ) x##y
#define MACRO_CONCAT( x, y ) CONCAT_IMPL( x, y )

#define FORlOOPCOUNTM MACRO_CONCAT(ForloopCountM,__LINE__)

#define for(args...)\
    int FORlOOPCOUNTM=0;\
for(args,FORlOOPCOUNTM++,forloopTrace(FORlOOPCOUNTM))\

int main()
{
    int i,j,x,y;
    j=100;
    y=200;
    for(i=0;i<j;i)   //works fine
    {
        i++;
        for(x=0;x<y;x) //works fine
            x++;
    }
    if(i>0)
       for(;i>0;)    //ERROR
         i--;
    for(;;)   //Error
    {
        i++;
    }

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

c c++

3
推荐指数
1
解决办法
144
查看次数

标签 统计

c++ ×2

c ×1

stl ×1

unordered-multimap ×1