小编Rob*_*edy的帖子

有没有办法用十六进制表达Postgres文字int?

我有一个十六进制数的大列表,我想插入PostgresQL表.我试过这样的事情:

INSERT INTO foo (i)
VALUES (0x1234);
Run Code Online (Sandbox Code Playgroud)

......但那没用.这可能吗?

sql postgresql

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

如何组合输出流,以便输出一次多个位置?

我想将两个(或更多)流组合成一个.我的目标是将任何输出定向到cout,cerr并且clog还将其与原始流一起输出到文件中.(例如,当事情记录到控制台时.关闭后,我仍然希望能够返回并查看输出.)

我在考虑做这样的事情:

class stream_compose : public streambuf, private boost::noncopyable
{
public:
    // take two streams, save them in stream_holder,
    // this set their buffers to `this`.
    stream_compose;

    // implement the streambuf interface, routing to both
    // ...

private:
    // saves the streambuf of an ios class,
    // upon destruction restores it, provides
    // accessor to saved stream
    class stream_holder;

    stream_holder mStreamA;
    stream_holder mStreamB;
};
Run Code Online (Sandbox Code Playgroud)

这看起来很简单.然后在main中的调用将是这样的:

// anything that goes to cout goes to both …
Run Code Online (Sandbox Code Playgroud)

c++ boost iostream stream tee

20
推荐指数
3
解决办法
8910
查看次数

为什么Delphi会在将ShortString分配给字符串时发出警告?

我正在将一些遗留代码转换为Delphi 2010.

有很多旧的ShortStrings,比如字符串[25]

为什么下面的作业:

type 
  S: String;
  ShortS: String[25];

...
S := ShortS;
Run Code Online (Sandbox Code Playgroud)

导致编译器生成此警告:

W1057 Implicit string cast from 'ShortString' to 'string'.
Run Code Online (Sandbox Code Playgroud)

这里没有数据丢失.在什么情况下这个警告对我有用?

谢谢!

Tomw

delphi

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

CodeIgniter如何知道cookie包含有效的会话数据?

在CodeIgniter中,会话数据默认保存在cookie中.但是我的服务器上必须还有一个文件(命名为会话ID)来验证数据(在cookie中)是否有效,或者我错了?

我正在搜索会话保存的位置.我已经查看了"session.save_path"目录(/ var/lib/php5),但是在这个目录中只有其他会话,而不是CodeIgniter会话.

我也没有在数据库中保存会话,所以CodeIgniter如何知道数据(在cookie中)是有效的?

php cookies session codeigniter

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

我在哪里可以获得图表的许多可区分颜色?

我正在寻找一个大约三十种颜色(RGB值)的列表,这些颜色非常不同,因此当在条形图中使用时,用户可以将每个条形匹配到图例中的该颜色.

有没有人有这样的颜色列表?

谢谢,

AJ

charts graphic-design colors

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

为什么static_cast(*this)到基类创建临时副本?

我正在阅读Effective C++并遇到了这个例子:

class Window {                                // base class
public:
  virtual void onResize() { ... }             // base onResize impl
  ...
};

class SpecialWindow: public Window {          // derived class
public:
  virtual void onResize() {                   // derived onResize impl;
    static_cast<Window>(*this).onResize();    // cast *this to Window,
                                              // then call its onResize;
                                              // this doesn't work!

    ...                                       // do SpecialWindow-
  }                                           // specific stuff

  ...

};
Run Code Online (Sandbox Code Playgroud)

这本书说:

您可能没想到的是它不会在当前对象上调用该函数!相反,强制转换创建了*this的基类部分的新临时副本,然后在副本上调用onResize!

为什么static_cast(上面的代码)创建一个新副本?为什么不只是使用对象的基类部分?

c++ casting effective-c++

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

如何在switch语句中选择一系列值?

当我尝试编译时,我收到此错误:

1>------ Build started: Project: snake, Configuration: Debug Win32 ------
1>  exercise.cpp
1>c:\users\robin\documents\visual studio 2010\projects\snake\snake\exercise.cpp(13): error C2059: syntax error : '>='
1>c:\users\robin\documents\visual studio 2010\projects\snake\snake\exercise.cpp(16): error C2059: syntax error : '>='
1>c:\users\robin\documents\visual studio 2010\projects\snake\snake\exercise.cpp(19): error C2059: syntax error : '>='
1>c:\users\robin\documents\visual studio 2010\projects\snake\snake\exercise.cpp(22): error C2059: syntax error : '>='
1>c:\users\robin\documents\visual studio 2010\projects\snake\snake\exercise.cpp(25): error C2059: syntax error : '>'
1>c:\users\robin\documents\visual studio 2010\projects\snake\snake\exercise.cpp(28): error C2059: syntax error : '=='
1>c:\users\robin\documents\visual …

c++ switch-statement

20
推荐指数
8
解决办法
13万
查看次数

为什么赋值运算符会返回对象的引用?

我正在修改我的C++,我正在处理运算符重载,特别是"="(赋值)运算符.我在网上看到并且遇到了讨论它的多个主题.在我自己的笔记中,我把所有的例子都记下来了

class Foo
{
    public:  
        int x;  
        int y;  
        void operator=(const Foo&);  
};  
void Foo::operator=(const Foo &rhs)
{
    x = rhs.x;  
    y = rhs.y;  
}
Run Code Online (Sandbox Code Playgroud)

在我在网上找到的所有参考文献中,我注意到操作符返回对源对象的引用.为什么返回对象的引用的正确方法而不是什么都没有?

c++ operator-overloading return-type assignment-operator

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

当auto用于数组时,为什么它被转换为指针而不是引用?

见下面的例子:

int arr[10];
int *p = arr; // 1st valid choice
int (&r)[10] = arr; // 2nd valid choice
Run Code Online (Sandbox Code Playgroud)

现在,当我们用auto反对arr的话,它选择的第一选择.

auto x = arr; // x is equivalent to *p
Run Code Online (Sandbox Code Playgroud)

是否有理由选择指针而不是数组的引用

c++ arrays language-design c++11

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

德尔福切割玻璃

我正在使用Delphi XE2,我喜欢玻璃效果,我想在Windows 7平板电脑工具中"切割"玻璃.如果你也知道如何切一个按钮,如果你告诉我如何,我会很高兴.

在此输入图像描述

谢谢

delphi aero-glass

18
推荐指数
1
解决办法
1301
查看次数