C语言中,如何将数组作为map的值存储?

2026-04-12 02:412阅读0评论SEO基础
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计275个文字,预计阅读时间需要2分钟。

C语言中,如何将数组作为map的值存储?

简要说明+C++中使用数组作为map容器Value值+内容+1)使用Vector容器代替数组+2)使用数组指针(数组不能循环利用)+int red[3]={1, 0, 0}; int green[3]={0, 1, 0}; int blue[3]={0, 0, 1}; st

C语言中,如何将数组作为map的值存储?

简述

C++中 使用数组作为map容器VAlue值

内容

1)是用Vector容器代替数组

2)使用数组指针(数组不能循环利用)

int red [ 3 ] = { 1 , 0 , 0 }; int green [ 3 ] = { 0 , 1 , 0 }; int blue [ 3 ] = { 0 , 0 , 1 }; std :: map < int , int ()[ 3 ]> colours ; colours . insert ( std :: pair < int , int ()[ 3 ]>(( GLUT_LEFT_BUTTON ,& red )); colours . insert ( std :: pair < int , int ()[ 3 ]>(( GLUT_MIDDLE_BUTTON ,& blue )); colours . insert ( std :: pair < int , int ()[ 3 ]>(( GLUT_RIGHT_BUTTON ,& green ));

3)使用结构体来构造代替数组的元素,或把数组直接放在结构体内(结构体可循环利用)

struct Triple { int color [ 3 ]; }; //Later in code Tripple red = { 1 , 0 , 0 }, green = { 0 , 1 , 0 }, blue = { 0 , 0 , 1 }; std :: map < int , Triple > colours ; colours . insert ( std :: pair < int , Triple >(( GLUT_LEFT_BUTTON , red )); colours . insert ( std :: pair < int , Triple >(( GLUT_MIDDLE_BUTTON , blue )); colours . insert ( std :: pair < int , Triple >(( GLUT_RIGHT_BUTTON , green ));

本文共计275个文字,预计阅读时间需要2分钟。

C语言中,如何将数组作为map的值存储?

简要说明+C++中使用数组作为map容器Value值+内容+1)使用Vector容器代替数组+2)使用数组指针(数组不能循环利用)+int red[3]={1, 0, 0}; int green[3]={0, 1, 0}; int blue[3]={0, 0, 1}; st

C语言中,如何将数组作为map的值存储?

简述

C++中 使用数组作为map容器VAlue值

内容

1)是用Vector容器代替数组

2)使用数组指针(数组不能循环利用)

int red [ 3 ] = { 1 , 0 , 0 }; int green [ 3 ] = { 0 , 1 , 0 }; int blue [ 3 ] = { 0 , 0 , 1 }; std :: map < int , int ()[ 3 ]> colours ; colours . insert ( std :: pair < int , int ()[ 3 ]>(( GLUT_LEFT_BUTTON ,& red )); colours . insert ( std :: pair < int , int ()[ 3 ]>(( GLUT_MIDDLE_BUTTON ,& blue )); colours . insert ( std :: pair < int , int ()[ 3 ]>(( GLUT_RIGHT_BUTTON ,& green ));

3)使用结构体来构造代替数组的元素,或把数组直接放在结构体内(结构体可循环利用)

struct Triple { int color [ 3 ]; }; //Later in code Tripple red = { 1 , 0 , 0 }, green = { 0 , 1 , 0 }, blue = { 0 , 0 , 1 }; std :: map < int , Triple > colours ; colours . insert ( std :: pair < int , Triple >(( GLUT_LEFT_BUTTON , red )); colours . insert ( std :: pair < int , Triple >(( GLUT_MIDDLE_BUTTON , blue )); colours . insert ( std :: pair < int , Triple >(( GLUT_RIGHT_BUTTON , green ));