-4
auto messwerte2 = { 3.5, 7.3, 4.9, 8.3, 4.4, 5.3, 3.8, 7.5 };

Which possibilities exist to access a single value explicitly of this array-like looking structure which as I was informed is actually a std::initializer_list ?

baxbear
  • 860
  • 3
  • 9
  • 27
  • I don't know how your loop looks like, and you don't show it, but chances are very much that if you read up on "arrays" you probably will stumble across the right `[]` syntax... and "loop" implies you iterate over individual elements (which implies that it demonstrates how to access a single one...) – Marcus Müller Oct 11 '16 at 13:45
  • Why is my question on -4? I had a problem, that came probably from a misunderstanding and confusing an array with a different structure of c++ language. How could I fix this question to be "better"? I mean, I received an answer that was directly focused to clarify my misunderstanding, if somebody else has the same problem this thread should help him, as it helped me. – baxbear Sep 15 '18 at 15:30

2 Answers2

4

Which possibilities exist to access a single value explicitly of this array?

It's not an array, but is deduced to a std::initializer_list<double> which can be accessed through an iterator or a range based loop:

#include <iostream>

auto messwerte2 = { 3.5, 7.3, 4.9, 8.3, 4.4, 5.3, 3.8, 7.5 };

int main() {

    for(auto x : messwerte2) {
        std::cout << x << std::endl;
    }
}

Live Demo

To make it an array use an explicit array declaration:

double messwerte2[] = { 3.5, 7.3, 4.9, 8.3, 4.4, 5.3, 3.8, 7.5 };
πάντα ῥεῖ
  • 1
  • 13
  • 116
  • 190
1
auto messwerte2 = { 3.5, 7.3, 4.9, 8.3, 4.4, 5.3, 3.8, 7.5 };

doesn't declare an array. It declares a std::initializer_list<double>

To declare an array, use:

double messwerte2[] = { 3.5, 7.3, 4.9, 8.3, 4.4, 5.3, 3.8, 7.5 };

Then you can use the regular array indexing syntax.

R Sahu
  • 204,454
  • 14
  • 159
  • 270