我有一个任意长度的字符串,从位置p0开始,我需要找到三个3字母模式之一的第一个出现.
假设字符串只包含字母.我需要找到从位置p0开始的三元组计数并以三元组向前跳,直到第一次出现'aaa'或'bbb'或'ccc'.
使用正则表达式甚至可以实现这一点吗?
我有很多包含代码片段,伪代码算法,类,模板,SQL样本等的小文件,我显然无法将所有这些文件放入库中.我需要一种实用的方法来索引所有这些方法,并且能够将这个索引提供给其他人.
我编写了一个基于矢量的3D编辑器(UI有点像技术图纸一样定制).我现在想以便携式格式保存矢量/绘图数据.有哪些格式; 哪一个(一个?)是最广泛接受的,哪里可以获得格式规范?
如何实现一个概念来使用 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) 不调用以下catch():
void test(void)
{
int i=1,j=0,k;
try
{
k = i/j;
}
catch(...)
{
...handle it...
}
}
Run Code Online (Sandbox Code Playgroud)
有没有办法捕捉到这种异常?
为什么编译器会在指定的行上抱怨?
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) 我不得不花费一些时间来查找并修复我在以下代码中设法隔离的错误:
#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 …
我的代码:
#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
不至少增加一次?
我试图找到如何使用谷歌在Linux上创建DLL-s,但获得了非常令人困惑的信息.
是否可以在linux上编写动态链接库?如果没有,是否还有其他方法可以从多个正在运行的程序中调用另一个模块中的代码?
c++ ×5
linux ×2
ambiguity ×1
c ×1
c++-concepts ×1
code-reuse ×1
exception ×1
file-format ×1
gcc ×1
perl ×1
regex ×1
search ×1
string ×1
try-catch ×1