mardi 5 avril 2016

The complier I used is gcc5.1 but it seems that he did't support c++11

#include <iostream>
#include <string>
int main()
{
    std::string s1 = "hello";
    std::cout << s1 << std::endl;

    for (auto c : s1)
        std::cout << c << std::endl;    

    return 0;
}

I think the code is right,but it had lots of error message(please ignore the name of the code):

D:>gcc hello.cpp -o hello

hello.cpp: In function 'int main()':

hello.cpp:8:12: error: 'c' does not name a type for (auto c : s1) ^

hello.cpp:11:2: error: expected ';' before 'return' return 0; ^

hello.cpp:11:2: error: expected primary-expression before 'return'

hello.cpp:11:2: error: expected ';' before 'return'

hello.cpp:11:2: error: expected primary-expression before 'return'

hello.cpp:11:2: error: expected ')' before 'return'

the book that i use to learn c++ is c++ primer,and i have learned c language before,but i still is freshmen.

Aucun commentaire:

Enregistrer un commentaire