注册 登录
编程论坛 C++教室

求教一下c++ lambda语句

yangboxionga 发布于 2015-05-08 21:18, 494 次点击
Microsoft Visual C++6.0编的程序   以前在学校电脑里弄得软件
#include <iostream>
//#include <string>
#include <vector>
#include <algorithm>

using namespace std;

void play(vector<int> &a)
{
    for_each( a.begin(),a.end(),[] (int &Element) {cout << Element << " ";} );
    cout << endl;
}
int main()
{
    vector<int> liang;
    liang.push_back(8);
    liang.push_back(89);
    liang.push_back(20);
    liang.push_back(257);

    play(liang);

    sort (liang.begin(),liang.end(),[](int &num1,int &num2) {return (num2 < num1);});

    paly(liang);

    return 0;
}


D:\1\c++\chengxu\hello\hello.cpp(10) : error C2059: syntax error : '['
D:\1\c++\chengxu\hello\hello.cpp(10) : error C2143: syntax error : missing ')' before '{'
D:\1\c++\chengxu\hello\hello.cpp(10) : error C2143: syntax error : missing ';' before '{'
D:\1\c++\chengxu\hello\hello.cpp(10) : error C2065: 'Element' : undeclared identifier
D:\1\c++\chengxu\hello\hello.cpp(10) : error C2059: syntax error : ')'
D:\1\c++\chengxu\hello\hello.cpp(23) : error C2059: syntax error : '['
D:\1\c++\chengxu\hello\hello.cpp(23) : error C2143: syntax error : missing ')' before '{'
D:\1\c++\chengxu\hello\hello.cpp(23) : error C2143: syntax error : missing ';' before '{'
D:\1\c++\chengxu\hello\hello.cpp(23) : error C2065: 'num2' : undeclared identifier
D:\1\c++\chengxu\hello\hello.cpp(23) : error C2065: 'num1' : undeclared identifier
D:\1\c++\chengxu\hello\hello.cpp(23) : error C2059: syntax error : ')'
D:\1\c++\chengxu\hello\hello.cpp(25) : error C2065: 'paly' : undeclared identifier
执行 cl.exe 时出错.


这个是怎么回事,和书里一模一样(除了变量名),求助一下,还是说我的软件不支持?
1 回复
#2
rjsp2015-05-11 16:20
还是说我的软件不支持?
--- VC++6 和 Turbo C++ 可以归为同一时期了
1