小编sla*_*ais的帖子

如何从某个起始位置找到字符串中第一次出现的模式?

我有一个任意长度的字符串,从位置p0开始,我需要找到三个3字母模式之一的第一个出现.

假设字符串只包含字母.我需要找到从位置p0开始的三元组计数并以三元组向前跳,直到第一次出现'aaa'或'bbb'或'ccc'.

使用正则表达式甚至可以实现这一点吗?

regex string perl search

6
推荐指数
3
解决办法
5723
查看次数

如何索引和提供可重用的代码?

我有很多包含代码片段,伪代码算法,类,模板,SQL样本等的小文件,我显然无法将所有这些文件放入库中.我需要一种实用的方法来索引所有这些方法,并且能够将这个索引提供给其他人.

  1. 这样的索引必须包含什么才能使搜索最容易?
  2. 网上有没有这样的存储库?(所以我可以测试他们使用的技术.)
  3. 是否已经编写了任何可以实现此功能的应用程序,我可以查看一下?

可能重复:https://stackoverflow.com/q/90300/15161

code-reuse

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

保存基于矢量的3D图形的格式

我编写了一个基于矢量的3D编辑器(UI有点像技术图纸一样定制).我现在想以便携式格式保存矢量/绘图数据.有哪些格式; 哪一个(一个?)是最广泛接受的,哪里可以获得格式规范?

file-format vector-graphics

5
推荐指数
1
解决办法
1304
查看次数

在C中生成"范围内"随机数

我需要生成[0,10]范围内的随机数,这样:

  • 所有数字都出现一次.
  • 没有重复的结果.

有人可以指导我使用哪种算法?

c

5
推荐指数
2
解决办法
343
查看次数

检查类是否可流式传输的概念

如何实现一个概念来使用 std::ostream 检查类型是否可流式传输?可能使用约束/ requires,但我通过谷歌找到的信息要么非常基本,要么也可以是克林贡语。

template<typename T> concept bool can_ostream()
{
    return check_if_operator<<(..)_is_in_T;  or something like this
}
Run Code Online (Sandbox Code Playgroud)

所以我可以使用它,例如:

template<can_ostream T> struct X { ... }
Run Code Online (Sandbox Code Playgroud)

c++ c++-concepts

5
推荐指数
1
解决办法
1404
查看次数

如何在Linux C++中捕获系统级异常?

不调用以下catch():

void test(void)
{
    int i=1,j=0,k;
    try
    {
        k = i/j;
    }
    catch(...)
    {
        ...handle it...
    }
}
Run Code Online (Sandbox Code Playgroud)

有没有办法捕捉到这种异常?

c++ linux exception try-catch

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

为什么我用这段代码得到了一个错误的错误?

为什么编译器会在指定的行上抱怨?

class C
{
    std::string s;
public:
    C() { s = "<not set>";}
    ~C() {}
    void Set(const std::string ss) { s=ss; }
    const std::string Get() { return s; }

    C &operator=(const C &c) { Set(c.Get()); return *this; }
    //error: passing ‘const C’ as ‘this’ argument of ‘const string C::Get()’
    // discards qualifiers [-fpermissive]


    //C &operator=(C &c) { Set(c.Get()); return *this; }   <-- works fine

};
Run Code Online (Sandbox Code Playgroud)

c++ compiler-errors

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

编译器没有拾取歧义

我不得不花费一些时间来查找并修复我在以下代码中设法隔离的错误:

#include <iostream>

struct A
{
    std::string S;
    A(const std::string s) { S = s; }
};

void f1(A a) { std::cout << "f1:a.S = " << a.S << "\n"; }
void f1(const std::string s) { std::cout << "f1:s = " << s << "\n"; }

void f2(A a) { std::cout << "f2:a.S = " << a.S << "\n"; }

int main()
{
    f1(A("test"));
    f1(std::string("test"));

    f2(A("test"));
    f2(std::string("test"));

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

这个错误是由f1函数创建的被忽略的(由我和编译器(?))模糊引起的:f2清楚地显示了这两者f1(A)并且f1(std::string)适用于A …

c++ ambiguity

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

为什么"n"在此函数中没有增加?

我的代码:

#include <iostream>
#include <vector>
#include <algorithm>

int test_n(std::vector<int>::iterator b, std::vector<int>::iterator e, int &n)
{
    n++;    
    std::vector<int>::difference_type l = e-b;

    if (l<100) return std::accumulate(b, e, 0);

    std::vector<int>::iterator tmp = b + l/2;
    int nL = test_n(b, tmp, n);
    int nR = test_n(tmp, e, n);

    return nL + nR;
}

int main()
{
    int n=0;
    std::vector<int> v;

    for (int i=1; i<1000; i++) v.push_back(i);
    std::cout << test_n(v.begin(), v.end(), n) << " (n=" << n << ")\n";
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

为什么n不至少增加一次?

c++

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

DLL在Linux上使用C++

我试图找到如何使用谷歌在Linux上创建DLL-s,但获得了非常令人困惑的信息.

是否可以在linux上编写动态链接库?如果没有,是否还有其他方法可以从多个正在运行的程序中调用另一个模块中的代码?

linux gcc shared-libraries

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