Reputation: 3
I'm currently studying about loops and I found this found and I programmed it on DevC++ and here's my code.
#include < iostream >
#include < vector >
using namespace std;
int main()
{
std::vector < std::string > names = {"Albert Einstein", "Stephen Hawking", "Michael Ellis"}; for(std::vector< std::string >::iterator it = names.begin(); it != names.end(); ++it) { std::cout << *it << std::endl; }
}
after compiling it I had problem and here's what the compiler said:
C:\Users\chesc\Pictures\image\loops.cpp In function 'int main()': 9 89
C:\Users\chesc\Pictures\image\loops.cpp [Error] in C++98 'names' must be initialized by constructor, not by '{...}'
9 89 C:\Users\chesc\Pictures\image\loops.cpp [Error] could not convert '{"Albert Einstein", "Stephen Hawking", "Michael Ellis"}' from '' to 'std::vector >'
Upvotes: 0
Views: 42
Reputation: 410
First, please format your question better. Put code into code sample.
To answer you. Your compiler is set to standard C++98. This standard does not allow the way of initialisation you used.
I suggest you to set your compiler for the newest standard it can support. It means C++11 and higher.
You can do it in Project Options -> Compiler -> Code Generation -> Language standards
Upvotes: 0