Primary expression problem

Hello, I've just started learning c++ from this website and when i tried to compile one of the programs shown in the tutorials it didn't work at all and i couldn't find a solution yet.
Sorry if I posted wrong, it's my first post here.

#include <iostream>
#include <string>
using namespace std;

int main ()
{
string str {"Hello!"};
for (char c : str)
{
std::cout << "[" << c << "]";
}
std::cout << '\n';
}



http://prntscr.com/9j1swu --- This is a screenshot of the errors and program


Last edited on
Although I don't see why the first error is generated, you should read:
http://www.cplusplus.com/articles/36vU7k9E/
It seems you compiler does not support C++11.

Try this:
1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>
#include <string>
using namespace std;

int main ()
{
string str = "Hello!";
for (size_t i = 0; i < str.size(); i++)
{
   std::cout << "[" << str[i] << "]";
}
std::cout << '\n';
}
thank you. your code works, i will read that article
Topic archived. No new replies allowed.