zoukankan      html  css  js  c++  java
  • Adding a struct into an array(stackoverflow)

    Question:

    So lets say I have a struct like this:

    struct example_structure 
    {
    int thing_one;
    int thing_two;
    };

    I also have an empty array which I am trying to fill with these structs. I am trying to add them as follows, but it doesn't seem to be working:

    array[i].thing_one = x;
    array[i].thing_two = y;

    Instead of this is there a way to declare a variable of type example_structure and then add that to the array?


    Answer:

    struct example_structure 
    {
        int thing_one;
        int thing_two;
    } myarray[100];

    And then you would access those array elements like any other array:

    myarray[10].thing_one=123;
    myarray[10].thing_two=456;

    if that is what you are trying to achieve.


    website:

    http://stackoverflow.com/questions/29353253/adding-a-struct-into-an-array

  • 相关阅读:
    windows服务程序
    DevExpress之时间控件
    DevExpress之列表控件
    Docker安装及基本使用
    配置阿里云yum源
    Centos7安装gitlab
    正则表达式
    sed进阶
    初识sed和gawk
    安装saltstack
  • 原文地址:https://www.cnblogs.com/vigorz/p/10499175.html
Copyright © 2011-2022 走看看