小编And*_*zos的帖子

std :: remquo目的和用法?

这个std::remquo功能的目的是什么?什么时候使用它而不是常规std::remainder函数?

c c++ floating-point c99 c++11

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

Eratosthenes的概率筛

考虑以下算法.

function Rand():
    return a uniformly random real between 0.0 and 1.0

function Sieve(n):

    assert(n >= 2)

    for i = 2 to n
        X[i] = true

    for i = 2 to n
        if (X[i])
            for j = i+1 to n
                if (Rand() < 1/i)
                    X[j] = false

    return X[n]
Run Code Online (Sandbox Code Playgroud)

Sieve(k)true作为k函数返回的概率是多少?

algorithm math

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

脚本获取git工作目录root?

可能重复:
有没有办法在一个命令中获取git根目录?

我正在编写一个bash脚本(实际上是一个Makefile),需要使用一个参数,该参数是一个相对于包含当前目录的git工作目录的根目录.

那是:

 /home/me$ git clone /abc/foo.git

 directory foo created

 /home/me$ cd foo/bar

 /home/me/foo/bar$ execute_script.sh

 hello /home/me/foo/baz
Run Code Online (Sandbox Code Playgroud)

execute_script.sh如下:

 echo hello `git something`/baz
Run Code Online (Sandbox Code Playgroud)

什么是git?它应该返回当前git工作根的绝对路径.

linux git bash

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

来自多个线程的同一个fd上的`select`

如果我select从多个线程调用相同的打开文件描述符会发生什么?

这是在某处记录的吗?

c linux networking

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

C String Literal必需的转义字符

我有一个零终止字符串:

char* s = ...;
Run Code Online (Sandbox Code Playgroud)

我正在生成C源代码(在运行时),我想输出一个表示s的字符串文字,它将在生成的C程序中生成与s相同的字符串.

我使用的算法是:

Output "

Foreach char c in s
    if c == " output \"
    else if c == \ output \\
    else output c

Output "
Run Code Online (Sandbox Code Playgroud)

除了"和之外我还需要特殊待遇\吗?

c string escaping

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

将配置参数从apache.conf传递到自定义apache C模块?

Apache httpd框架中是否有任何机制允许我将自定义参数从Apache配置文件传递到自定义Apache模块(使用C API编写)?我真的只需要键/值对.

在conf文件中的东西:

ConfigParameter foo bar
Run Code Online (Sandbox Code Playgroud)

然后在代码中:

string foo = GetApacheConfigParameter("foo"); // = "bar"
Run Code Online (Sandbox Code Playgroud)

c apache

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

C++ 11:在std :: array <char,N>上定义函数

std::array 采用两个模板参数:

typename T // the element type
size_t N // the size of the array
Run Code Online (Sandbox Code Playgroud)

我想定义一个函数,它将std :: array作为参数但仅针对特定的T,在这种情况下char,但对于任何大小的数组:

以下是不正确的:

void f(array<char, size_t N> x) // ???
{
    cout << N;
}

int main()
{
    array<char, 42> A;

    f(A); // should print 42

    array<int, 42> B;

    f(B); // should not compile
}
Run Code Online (Sandbox Code Playgroud)

写这个的正确方法是什么?

c++ c++11

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

`X :: X(const X &&)`Const移动构造函数?

可能重复:
移动构造函数签名

struct X
{
    X(X&);         // (1)
    X(X&&);        // (2)
    X(const X&);   // (3)
    X(const X&&);  // (4)
};
Run Code Online (Sandbox Code Playgroud)

是否有任何情况(4)会在重载决议中被选中?

c++ c++11

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

C++ GMP库ostream运算符<<编译但不链接?

$ apt-cache show libgmp10
Package: libgmp10
...
Version: 2:5.0.2+dfsg-2ubuntu2
Run Code Online (Sandbox Code Playgroud)

test.cpp:

#include <gmpxx.h>
#include <iostream>

using namespace std;

int main()
{
    mpz_class x = 42;

    cout << x;
}
Run Code Online (Sandbox Code Playgroud)

编译:

$ g++ -c test.cpp -o test.o
$
Run Code Online (Sandbox Code Playgroud)

链接:

$ g++ test.o -lgmp
test.o: In function `std::ostream& operator<<
    <__mpz_struct [1]>(std::ostream&,
         __gmp_expr<__mpz_struct [1],
              __mpz_struct [1]> const&)':

test.cpp:(.text._ZlsIA1_12__mpz_structERSoS2_RK10__gmp_exprIT_S4_E[_ZlsIA1_12__mpz_structERSoS2_RK10__gmp_exprIT_S4_E]+0x2a):

undefined reference to `operator<<(std::ostream&, __mpz_struct const*)'
collect2: error: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)

operator<<(ostream&, mpz_class)在链接时找不到.是什么赋予了?

c++ linux gmp

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

Qt"hello world"GUI应用程序没有链接?

可能重复:
Qt:信号和插槽错误:未定义引用`vtable for

这里我们有test.cpp:

#include <QApplication>
#include <QMainWindow>

class MainWindow : public QMainWindow
{
    Q_OBJECT
};

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    MainWindow w;
    w.show();

    return a.exec();
}
Run Code Online (Sandbox Code Playgroud)

单独放在一个新目录中:

$ qmake -project
$ qmake
$ make
Run Code Online (Sandbox Code Playgroud)

它不起作用:

test.o: In function `MainWindow::~MainWindow()':
test.cpp:(.text._ZN10MainWindowD2Ev[_ZN10MainWindowD5Ev]+0x3): undefined reference to `vtable for MainWindow'
test.cpp:(.text._ZN10MainWindowD2Ev[_ZN10MainWindowD5Ev]+0xb): undefined reference to `vtable for MainWindow'
test.o: In function `main':
test.cpp:(.text.startup+0x48): undefined reference to `vtable for MainWindow'
test.cpp:(.text.startup+0x51): undefined reference to `vtable for MainWindow'
test.o: In function `MainWindow::~MainWindow()': …
Run Code Online (Sandbox Code Playgroud)

c++ qt

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

标签 统计

c++ ×5

c ×4

c++11 ×3

linux ×3

algorithm ×1

apache ×1

bash ×1

c99 ×1

escaping ×1

floating-point ×1

git ×1

gmp ×1

math ×1

networking ×1

qt ×1

string ×1