lambda expression under g++ compiler in linux

2019-08-04 12:42发布

i need to to use c++ find_if() lambda expression, in my vc compiler it compiles without any errors, and i can't compile it in linux:debian:g++4.4 :

-CPP function:

    istream_iterator<string> it = find_if(istream_iterator<string>(ss),
        f,
        [=](const string& str)
        {return str == to_string(urlHash);});

-Error output:

    -error: expected primary-expression before '[' token
    -error: expected primary-expression before '=' token
    -error: expected primary-expression before ']' token
    -error: expected primary-expression before 'const'

question 1 : is this a version related problem of c++, despite using the -std=c++0x flag, nothing changes.

question 2 : i can't use -std=c++11 flag, despite that i installed the gcc 4.7 in my machine.

thanks;

2条回答
地球回转人心会变
2楼-- · 2019-08-04 13:12

if you guys interested in this i found a way to install gcc-4.7 by building it your self in every linux system link:

http://gcc.gnu.org/install/

查看更多
闹够了就滚
3楼-- · 2019-08-04 13:19

question 1 : is this a version related problem of c++, despite using the -std=c++0x flag, nothing changes.

Yes. Lambdas are not supported in GCC 4.4. You will need to upgrade to or install version 4.5 or higher. See here for more details.

question 2 : i can't use -std=c++11 flag, despite that i installed the gcc 4.7 in my machine.

That is not a question.

查看更多
登录 后发表回答