小编viv*_*vek的帖子

在成员函数内的lambda捕获列表中使用成员变量

以下代码使用gcc 4.5.1编译,但不使用VS2010 SP1编译:

#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include <set>
#include <algorithm>

using namespace std;
class puzzle
{
        vector<vector<int>> grid;
        map<int,set<int>> groups;
public:
        int member_function();
};

int puzzle::member_function()
{
        int i;
        for_each(groups.cbegin(),groups.cend(),[grid,&i](pair<int,set<int>> group){
                i++;
                cout<<i<<endl;
        });
}
int main()
{
        return 0;
}
Run Code Online (Sandbox Code Playgroud)

这是错误:

error C3480: 'puzzle::grid': a lambda capture variable must be from an enclosing function scope
warning C4573: the usage of 'puzzle::grid' requires the compiler to capture 'this' but the current default capture mode does …
Run Code Online (Sandbox Code Playgroud)

c++ lambda visual-studio-2010 c++11

127
推荐指数
4
解决办法
13万
查看次数

在C++中使用异常的typedef

我在C++中遇到了关键字typedef的新用法.

这个typedef语句是什么意思?

int typedef foo;
Run Code Online (Sandbox Code Playgroud)

c++ typedef

52
推荐指数
2
解决办法
1040
查看次数

Fragment.setUserVisibleHint()是由android系统调用的吗?

Fragment.setUserVisibleHint()系统调用的方法,还是
我们手动调用它?

android

25
推荐指数
1
解决办法
2万
查看次数

Http通过telnet与python和扭曲

这就是我想要做的:

web-browser - >通过telnet(server1)连接到远程服务器 - >通过端口80(server2)上的telnet连接到squid-proxy(需要身份验证)

我写了一个使用Twisted的小python脚本(这里:

#! /usr/bin/python
from twisted.internet import reactor, protocol
from twisted.web import http
from telnetlib import Telnet
import getpass
from sys import stdout

class datareceiver(protocol.Protocol):
    def dataReceived(self,data):
        self.telnet_con.write(data)
        stdout.write( self.telnet_con.read_all() )

    def connectionMade(data):
        stdout.write("\nA connection was made to this server\n")

def main():
    server1 = "10.1.1.1"
    #user = raw_input("Enter your remote account: ")
    password = getpass.getpass()
    tn = Telnet(server1)

    if password:
        tn.read_until("Password: ")
        tn.write(password + "\n")

    #This is server2
    tn.write("telnet 10.1.1.10 80 \n")


    #serverfac = protocol.Factory() …
Run Code Online (Sandbox Code Playgroud)

python proxy twisted telnet

6
推荐指数
1
解决办法
1120
查看次数

简单的Java正则表达式匹配器无法正常工作

代码:

import java.util.regex.*;

public class eq {
    public static void main(String []args) {
        String str1 = "some=String&Here&modelId=324";
        Pattern rex = Pattern.compile(".*modelId=([0-9]+).*");
        Matcher m = rex.matcher(str1);
        System.out.println("id = " + m.group(1));
    }
}
Run Code Online (Sandbox Code Playgroud)

错误:

Exception in thread "main" java.lang.IllegalStateException: No match found
Run Code Online (Sandbox Code Playgroud)

我在这做错了什么?

java regex

6
推荐指数
1
解决办法
7267
查看次数

访问std :: pair数组的元素时出错

我已经定义了一对数组,如下所示:

std::pair<int,int> delta[4];
delta[0] = std::make_pair(0,1);
delta[1] = std::make_pair(1,1);
delta[2] = std::make_pair(1,0);
delta[3] = std::make_pair(1,-1);
Run Code Online (Sandbox Code Playgroud)

但是当我尝试访问以下元素时:

delta[2].first
Run Code Online (Sandbox Code Playgroud)

我收到如下错误:

binary '[' : 'std::pair<_Ty1,_Ty2>' does not define this operator or a conversion to a type acceptable to the predefined operator
error C2228: left of '.first' must have class/struct/union
Run Code Online (Sandbox Code Playgroud)

这是我访问它的功能:

#include <fstream>
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>

int who_won(std::pair<int,int> &delta,std::vector<std::vector<int>> &grid);

int main(int argc, char** argv)
{
    std::fstream input;
    input.open("E:\\in.txt",std::ios_base::in);
    std::string line;
    char ch;
    std::vector<std::vector<int>> grid;
    std::vector<int> row; …
Run Code Online (Sandbox Code Playgroud)

c++ arrays stl std-pair

3
推荐指数
1
解决办法
2488
查看次数

从python登录到MongoDB

我想使用python将一些信息记录到mongodb中.我发现2个库mongodblog和log4mongo用于python.任何一个更好的想法?还是比这些更好的任何其他图书馆?

python logging mongodb

3
推荐指数
1
解决办法
4999
查看次数

如何在单个delete语句中删除多个动态分配的数组?

如果我有三个指针加倍:

rdf1 = new double [n];

rdf2 = new double [n];

rdf3 = new double [n];
Run Code Online (Sandbox Code Playgroud)

我想用一个删除语句删除它们.就像是 :

delete [] rdf1,rdf2,rdf3;
Run Code Online (Sandbox Code Playgroud)

什么是正确的方法呢?

c++ pointers dynamic delete-operator

2
推荐指数
3
解决办法
3171
查看次数

扭曲延迟回调中的奇怪行为

目标:尝试与服务器列表建立TCP连接,并在连接成功并提示输入密码时进行打印

问题:似乎to_check -= 1我的回调(名为connected)和errback(名为failed)中的statement()永远不会被执行,即使这些函数中的print语句是.

from twisted.internet import protocol, defer
import sys

class myProto(protocol.Protocol):
    got = ''
    def dataReceived(self,data):
        #print data
        self.got += data
        if "Password:" in data:
            self.transport.loseConnection()

    def connectionLost(self,reason):
        #print self.got
        if "Password:" in self.got:
            self.factory.success("and was prompted for password")
        else:
            self.factory.success("But was not prompted for password")

class myFactory(protocol.ClientFactory):
    protocol = myProto

    def __init__(self,deferred,host):
        self.deferred = deferred
        self.host = host
        print "Trying Connection to %s ..." % host

    def success(self,askpass):
        if self.deferred is …
Run Code Online (Sandbox Code Playgroud)

python twisted callback

2
推荐指数
1
解决办法
496
查看次数

Seg Fault在C++容器上循环

这是代码(找到2组的联合):

template <class dtype>
void printSet(dtype data)
{
    std::cout<<"\n";
    for(auto i = data.begin(); i != data.end(); i++)
    {
        std::cout<<*i<<" ,";
    }
}

int main(int argc, char const *argv[])
{
    int arr[] = {1,2,3,4,5};
    std::set<long long> a(arr, arr + 5), b(arr, arr + 5), c;
    std::vector<long long> v;
    b.insert(1000);
    printSet(a);
    printSet(b);
    set_union(a.begin(), a.end(), b.begin(), b.end(), v.begin());
    printSet(v);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

这就是我得到的:

1 ,2 ,3 ,4 ,5 ,
[1]    9444 segmentation fault  ./a.out
Run Code Online (Sandbox Code Playgroud)

我在哪里搞砸了?

c++ std

0
推荐指数
2
解决办法
156
查看次数