lundi 24 avril 2017

This should be proper usage for the for each loop in c++11 [on hold]

Here is my program. I am getting an error when using the element variable from the for each loop.

#include <iostream>
#include <array>
#include <algorithm>

int main() {

  std::array<int, 5> myarray[] { 7, 3, 1, 9, 5 };

  for(const auto &element : myarray)
    std::cout << element << std::endl;

  std::sort(myarray.begin(), myarray.end());

  for(const auto &element : myarray)
    std::cout << element << std::endl;

  return 0;
}

Here is my Makefile

CFLAGS=-Wall -g3 -std=c++11
OPTIONS=-fdiagnostics-color=auto


all: main

main:
    g++ $(CFLAGS) $(LIBS) $(OPTIONS) -o main main.cpp

clean:
    rm -rf main

What am I doing wrong?

Aucun commentaire:

Enregistrer un commentaire