小编mel*_*ene的帖子

PostgreSQL中单引号和双引号有什么区别?

我是PostgresSQL的新手.我试过了

select * from employee where employee_name="elina";
Run Code Online (Sandbox Code Playgroud)

但结果错误如下:

ERROR: column "elina" does not exist.
Run Code Online (Sandbox Code Playgroud)

然后我尝试用单引号替换双引号,如下所示:

select * from employee where employee_name='elina';
Run Code Online (Sandbox Code Playgroud)

结果很好.那么postgresql中的单引号和双引号有什么区别.如果我们不能在postgres查询中使用双引号,那么如果在postgreSQL中使用这个双引号有什么其他用途?

sql postgresql

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

std :: pair <int,std :: string>是否定义良好?

似乎我可以对a进行排序std::vector<std::pair<int, std::string>>,std::pair它将根据int值进行排序.这是一个定义明确的事情吗?

是否std::vector<std::pair<int, std::string>>有基于它的元素的默认排序?

c++ sorting stl

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

如何忽略项目中的同名目录__pycache__?

__pycache__目录在使用 git 更新时很烦人。每当我使用 时git status,都会出现很多 .pyc 文件。如何方便地列出__pycache__文件中的文件夹,.gitignore以便在使用时不显示git status

例如:

core/__pycache__/utils.cpython-36.pyc
core/__pycache__/version.cpython-36.pyc
core/actions/__pycache__/__init__.cpython-36.pyc
core/actions/__pycache__/action.cpython-36.pyc
Run Code Online (Sandbox Code Playgroud)

我是否必须将所有单个__pycache__文件都列出到 gitignore 文件中?

git gitignore

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

我能说出一个程序是用哪个ghc版本构建的吗?

我想知道是否有办法告诉哪个ghc版本是二进制文件.主要版本就够了,特别是ghc 7 vs ghc 8.

haskell ghc

17
推荐指数
1
解决办法
272
查看次数

无法将预期类型"文本"与实际类型"[Char]"匹配

这可能是一个非常愚蠢的问题,但我无法解决这个问题(因为我刚开始学习Haskell).

我有一个简单的代码块:

module SomeTest where
import Data.Text

str =  replace "ofo" "bar" "ofofo"
Run Code Online (Sandbox Code Playgroud)

如果我打电话给str我,我得到:

<interactive>:108:19: error:
* Couldn't match expected type `Text' with actual type `[Char]'
* In the first argument of `Data.Text.replace', namely `"ofo"'
  In the expression: Data.Text.replace "ofo" "bar" "ofofo"
  In an equation for `it': it = Data.Text.replace "ofo" "bar" "ofofo"

<interactive>:108:25: error:
* Couldn't match expected type `Text' with actual type `[Char]'
* In the second argument of `Data.Text.replace', namely `"bar"'
  In the expression: Data.Text.replace …
Run Code Online (Sandbox Code Playgroud)

haskell

16
推荐指数
1
解决办法
6743
查看次数

c ++模板奇怪的优化

我像boost一样写了一个单例模板类:

template <typename _T>
class Singleton
{ 
    public :
    static _T* Instance()
    {
        static _T obj;
        return &obj;
    }

protected :
    Singleton() {}

private :
    struct ObjectCreator
    {
        ObjectCreator()
        {
            Singleton<_T>::instance();
        }
    };

    static ObjectCreator object_creator;
};

template <typename _T>
typename Singleton<_T>::ObjectCreator Singleton<_T>::object_creator;
Run Code Online (Sandbox Code Playgroud)

我写了主要功能来测试它.

#include "Singleton.h"
class A : public Singleton <A>
{
    public:
        int a;
};


int main()
{
    A::Instance()->a = 2;
}
Run Code Online (Sandbox Code Playgroud)

我知道我错误地输入了Instance in ObjectCreator的构造函数,奇怪的是我可以通过gcc-4.4.7正确编译它,然后我使用了clang-6.0,它打了我的错字.

我猜gcc可以做一些优化,因为我没有做任何事情ObjectCreator,所以它忽略了错误代码.

我有两个问题:

  1. 我应该怎么做让gcc报告我错误(不改变我的代码),比如添加一些编译器标志?
  2. 如果有人对此有更可靠的解释?一些官方文件会这样做.

Ps:我知道boost会添加一个do_nothing函数ObjectCreate …

c++ gcc templates clang

16
推荐指数
1
解决办法
435
查看次数

sizeof的成本是多少?

sizeof的成本是多少?

我希望:

  • sizeof(someclass)可以在编译时知道
  • sizeof(someStaticArray)可以在编译时知道
  • sizeof(someDynamicArray)在编译时无法识别

那最后一个案例是如何运作的呢?

c++

15
推荐指数
3
解决办法
4178
查看次数

从字符类中排除字符

是否有一种简单的方法来匹配类中除了某些特定组之外的所有字符?例如,如果在我可以使用\ w来匹配所有unicode单词字符集的语言中,有没有办法从该匹配中排除像下划线"_"这样的字符?

只有想到的想法是在每个角色周围使用负向前瞻/后面,但是当我有效地想要将角色与正匹配和负匹配匹配时,这似乎比必要更复杂.例如,如果&是一个AND运算符,我可以这样做......

^(\w&[^_])+$
Run Code Online (Sandbox Code Playgroud)

regex set-difference character-class

14
推荐指数
5
解决办法
6377
查看次数

为什么第二个scanf()不会执行

我正在尝试执行这段代码.

#include <stdio.h> 
int main(void)
{       

     printf("Start from here\n");
     int e, f, g, h;

     scanf("%d,%d", &e, &f);
     scanf("%d, %d", &g, &h);

     printf("%d %d %d %d", e, f, g, h);
}
Run Code Online (Sandbox Code Playgroud)

当我输入2,0或匹配第一个格式字符串的东西时,scanf()第二个scanf()也执行.

但是,如果我输入类似于2-0第一个的东西scanf(),程序会跳过第二个scanf()并直接进入printf()

例如,这是程序样本运行的输入和输出.第二行是输入.

Start from here
1-2  
1 0 -2 -856016624u
Run Code Online (Sandbox Code Playgroud)

注意程序如何完全跳过第二个scanf(),并直接进入printf().为什么第二个scanf()被跳过这里?

c scanf

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

用于在初始化期间表示数组大小的有效和无效语法

我目前正在研究c阵列,并且对在初始化期间能够和不能用于表示阵列大小的内容感到困惑.

我是正确的假设

#define SIZE 5 
Run Code Online (Sandbox Code Playgroud)

const int SIZE = 5; 
Run Code Online (Sandbox Code Playgroud)

从根本上是不同的?

他们有区别,一个让我感到困惑的特殊例子

#define SIZE 5
int arr[SIZE] = {11, 22, 33, 44, 55}; 
Run Code Online (Sandbox Code Playgroud)

是有效的语法,但是

const int SIZE = 5;
int arr[SIZE] = {11, 22, 33, 44, 55};
Run Code Online (Sandbox Code Playgroud)

是无效的语法.虽然有趣,

const int SIZE = 5;
int arr[SIZE];
Run Code Online (Sandbox Code Playgroud)

是有效的语法.

特定语法是有效还是无效的背后的逻辑是什么?

c arrays

14
推荐指数
3
解决办法
558
查看次数

标签 统计

c++ ×3

c ×2

haskell ×2

arrays ×1

character-class ×1

clang ×1

gcc ×1

ghc ×1

git ×1

gitignore ×1

postgresql ×1

regex ×1

scanf ×1

set-difference ×1

sorting ×1

sql ×1

stl ×1

templates ×1