小编Pio*_*ost的帖子

为什么我的Boost.Regex搜索只报告一次匹配迭代?

我试图找出字符串中有多少正则表达式匹配.我正在使用迭代器迭代匹配,并使用整数来记录有多少.

long int before = GetTickCount();
string text;

boost::regex re("^(\\d{5})\\s(\\d{8})\\s(.*)\\s(.*)\\s(.*)\\s(\\d{8})\\s(.{1})$");
char * buffer;
long length;
long count;
ifstream f;


f.open("c:\\temp\\test.txt", ios::in | ios::ate);
length = f.tellg();
f.seekg(0, ios::beg);

buffer = new char[length];

f.read(buffer, length);
f.close();

text = buffer;
boost::sregex_token_iterator itr(text.begin(), text.end(), re, 0);
boost::sregex_token_iterator end;

count = 0;
for(; itr != end; ++itr)
{
    count++;
}

long int after = GetTickCount();
cout << "Found " << count << " matches in " << (after-before) << " ms." << endl;
Run Code Online (Sandbox Code Playgroud)

在我的例子中,count总是返回1,即使我把代码放在for循环中以显示匹配(并且有很多).这是为什么?我究竟做错了什么? …

c++ regex iterator greedy boost-regex

4
推荐指数
1
解决办法
3214
查看次数

C++ :: Boost :: posix_time(经过的秒数.经过的小数秒)

我试图找到两个一开始看起来并不难的问题的答案.Q1:如何获取UTC.Now()和给定日期之间经过的秒数?A1:就像下面的代码一样!Q2:如何确定自上一次"完整"秒后经过的小数秒数?我想打印"total_elapsed_seconds.fractional_seconds" - >"1234124.45".我怎么做?A2 : ???

#include <iostream>
#include <boost/date_time/gregorian/gregorian.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>

using namespace std;
using namespace boost::gregorian;
using namespace boost::posix_time; 

void main()
{
    ptime Jan1st1970(date(1970, 1, 1));
    for(int i = 0; i < 10; i++)
    {
        ptime Now = second_clock::universal_time();
        time_duration diff = Now - Jan1st1970;
        cout << Now << " : " << diff.total_seconds() << "." << diff.fractional_seconds() << endl;
    }
}
Run Code Online (Sandbox Code Playgroud)

c++

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

Boost :: any和polymorphism

boost::any用来存储指针,并想知道是否有提取多态数据类型的方法.

这是一个理想情况下我想做的简单示例,但目前无效.

struct A {};

struct B : A {};

int main() {

    boost::any a;
    a = new B();
    boost::any_cast< A* >(a);
}
Run Code Online (Sandbox Code Playgroud)

这失败是因为a正在存储B*,而我正在尝试提取A*.有没有办法实现这个目标?

谢谢.

c++ polymorphism boost-any

4
推荐指数
1
解决办法
2221
查看次数

提升图表库和访问者

我正在编写一个用于操作键图的库,我正在使用Boost Graph Library为我存储数据.不幸的是,我似乎无法弄清楚如何使用它来实现正确的访问者模式,因为你不能将顶点子类化 - 你必须依赖'属性'.库中提供的访问者框架似乎非常适合使用某些算法,其中顶点都是相同的类型,但存储不同的信息.在我的问题中,顶点具有不同的类型并存储不同类型的信息 - 一些顶点是电阻器,而一些是电容器等.我如何编写基于顶点属性工作的访问者模式,而不是顶点本身?

到目前为止,我唯一想到的是编写一个小类来表示一个对象的类型,该对象指向我需要获取图形信息的原始顶点.然而,这似乎非常kludgy,邪恶的工作.

c++ visitor boost-graph

4
推荐指数
2
解决办法
4327
查看次数

32位到64位sql server 2008数据库转换

我们正在将数据库从运行sql 2005的旧32位硬件迁移到带有sql 2008 64位的新硬件.我的问题是,如果数据库在新服务器上重新附加后,或者在64位实例上以32位模式运行,数据库是否自动转换为64位.有办法告诉吗?

sql sql-server-2008 32bit-64bit

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

什么是重新排序由dicts组成的列表的Pythonic方法?

我有以下列表:

list = [{'nr' : 2, 'name': 'streamname'}, {'nr' : 3,'name': 'streamname'}, {'nr' : 1, 'name': 'streamname'}]
Run Code Online (Sandbox Code Playgroud)

那么我如何在python中以高效的方式重新排序呢?

list = [{'nr' : 1, 'name': 'streamname'}, {'nr' : 2,'name': 'streamname'}, {'nr' : 3, 'name': 'streamname'}]
Run Code Online (Sandbox Code Playgroud)

我想出了使用sort并创建一个lambda函数来对它进行排序.这是一个好方法吗?它有效吗?

list.sort(cmp=lambda x,y: cmp(x['nr'], y['nr']))
Run Code Online (Sandbox Code Playgroud)

python sorting lambda

4
推荐指数
1
解决办法
195
查看次数

为什么mod_wsgi不支持Windows上的守护进程模式?

http://code.google.com/p/modwsgi/上可以阅读此声明

的mod_wsgi的守护模式将然而,仅可在Apache 2.0或2.2 UNIX上运行,只有当基本的Apache Apache的运行时库已编制与线程支持.

在Windows下不支持守护进程模式的原因是什么?

在得到之后我发现了上述内容

Invalid command 'WSGIDaemonProcess', perhaps misspelled or defined by a module not included in the server configuration
Run Code Online (Sandbox Code Playgroud)

来自Apache的错误.模块的包含不是问题,因为WSGIScriptAlias指令工作正常.我想我得到的错误是由于mod_wsgi的wiki上描述的限制.

python windows apache mod-wsgi

4
推荐指数
1
解决办法
1937
查看次数

Python请求模块和JSON响应

我使用了很棒的 Requests模块来测试我为我们的一个内部项目创建的API.我相信我已经发现了Requests模块本身的缺陷,或者我使用它的缺陷.

由于我们的数据不是超敏感的,因此我们的API使用简单的基本HTTP身份验证来控制访问.当我做了API URL的请求,使用JSON作为数据格式,要么用的urllib2或HTTPBasicAuthHandler PHP和卷曲,我得到我的数据备份的格式正确的JSON字符串 - 没问题.

但是,当我使用Requests模块发出相同的请求时,我得到一个编码的字符串,我无法确定它是什么类型的编码.这是该字符串开头的片段:

\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\x03\xadZ\xfb\x8f\xd3H\x12\xfeWzG\xab;\x90
Run Code Online (Sandbox Code Playgroud)

以下是我使用请求重现此问题的几行代码:

import requests
# api_user and api_pw not printed here for security reasons
r = requests.get('http://ourdomain.com/api/featured/school/json', auth=(api_user, api_pw))
status = r.status_code # Produces 200 every time
rawdata = r.read()
print rawdata
Run Code Online (Sandbox Code Playgroud)

每次我这样做,我都会得到编码的字符串.

任何人都可以帮我确定:a)什么编码(对于我自己的启发),和b)为什么请求返回该编码中的数据,以及如何解码和/或"修复"它.

提前致谢!

python json http-request python-requests

4
推荐指数
1
解决办法
4583
查看次数

在Python中,如何确定可迭代对象是否具有稳定的迭代顺序?

在Python中,如何确定可迭代对象是否具有稳定的迭代顺序?

collections.Iterable抽象的基类,但没有稳定的对应类。

我问的原因是为了能够防止用户或不稳定的迭代顺序(警告他们,当他们通过考试(错误)迭代dictset等等)的函数,其中迭代的稳定性是至关重要的。

python collections abstract-class iterator

4
推荐指数
1
解决办法
531
查看次数

在Windows下克隆git repo时我得到"错误:无法创建文件<file> ...(是一个目录)"

Z:\>git clone git://github.com/kennethreitz/httpbin.git
Cloning into 'httpbin'...
remote: Counting objects: 1073, done.
remote: Compressing objects: 100% (401/401), done.
remote: Total 1073 (delta 672), reused 1045 (delta 651)
Receiving objects: 100% (1073/1073), 114.42 KiB | 128 KiB/s, done.
Resolving deltas: 100% (672/672), done.
error: unable to create file httpbin/templates/... (Is a directory)
Run Code Online (Sandbox Code Playgroud)

git版本1.8.0.msysgit.0,Windows Vista SP2 x64

怎么了?

windows git msysgit

4
推荐指数
1
解决办法
5258
查看次数