-2
#include <iostream>
#include <stdlib.h>
#include <cstring>

using namespace std;

int main()
{
   string ID[]={"620301025123"}; //ID array

   long long int IC[10]={0}; //IC array

   // loop to change the ID string to Array IC. I will want to increase the size 
   // of ID array, later on, to put in new data but for now, I'm just using one data
   // which is "620301025123" first.

   for(int i = 0; i < 10; ++i){
     IC[i]= {atoll(ID[i].c_str())};
   }
 }

The error I got is:

14 29 C:\Users\ASUS\Desktop\Assign1\Untitled3.cpp [Warning] extended initializer lists only available with -std=c++11 or -std=gnu++11*/

Jabberwocky
  • 48,281
  • 17
  • 65
  • 115
  • Please provide a [mcve], take [the tour](https://stackoverflow.com/tour) and read [the help page](https://stackoverflow.com/help). Welcome to SO. – Ron Mar 01 '18 at 09:13
  • 2
    1) Are you compiling with C++11 support enabled, as the error suggests? 2) Such a `for` loop, with `ID[i].c_str()`invokes undefined behavior, due to going out of bounds of array `ID`, since it contains exactly one element. 3) Consider learning from a [good C++ book](https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list) instead of coding randomly. – Algirdas Preidžius Mar 01 '18 at 09:15
  • Why you used `c_str()` ? – Mohammad Kanan Mar 01 '18 at 09:22
  • I expect this: `IC[i]= {atoll(ID[i])};` – Mohammad Kanan Mar 01 '18 at 09:25
  • Beware: `string ID[] = { "620301025123" };` declares an array of `string` containing exactly one string (`"620301025123"`). Therefore `ID[1]` is incorrect and will lead to _undefined behaviour_ (google that term). Please tell us what you expect `IC` to contain after the `for` loop. – Jabberwocky Mar 01 '18 at 09:41

1 Answers1

1

First of all: it's #include <cstdlib> in C++.

Then, your problem does not seem to be the conversion to long long, but the initialization of the string, at least that's what the warning (not an error) says. You are using extended initializer lists, which are C++11, but haven't activated C++11 support.

The warning tells you how to activate it.

And finally: Don't get in the habit of using using namespace, at least not globally. You can use using on specific symbols, but even this I'd only do locally, and never globally.

Demosthenes
  • 1,515
  • 10
  • 22