小编Che*_*eng的帖子

构造函数的参数命名

在Java中,通常,我可以将构造函数的参数与成员变量同名.

public A(int x)
{
    this.x = x;
}

private int x;
Run Code Online (Sandbox Code Playgroud)

在C++中,我不能.通常,我必须这样做.

public:
    A(int x_) : x(x_) 
    {
    }

private:
    int x;
Run Code Online (Sandbox Code Playgroud)

有没有更好的方法?由于构造函数参数名称看起来很难看,当IDE IntelliSense弹出构造函数参数窗口时.

c++

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

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

将std :: string转换为特定于MSVC的__int64

我可以知道如何将std :: string转换为特定于MSVC的__int64吗?

c++

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

快速确定64位中最右边第n位的方法

我尝试确定最右边的第n位集

if (value & (1 << 0)) { return 0; }
if (value & (1 << 1)) { return 1; }
if (value & (1 << 2)) { return 2; }
...
if (value & (1 << 63)) { return 63; }
Run Code Online (Sandbox Code Playgroud)

如果比较需要做64次.有没有更快的方法?

c++

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

根据插入序列对地图键进行排序

没有其他容器(如矢量)的帮助,我是否可以使地图的键与插入序列的顺序相同?

#include <map>
#include <iostream>

using namespace std;

int main()
{
  map<const char*, int> m;
  m["c"] = 2;
  m["b"] = 2;
  m["a"] = 2;
  m["d"] = 2;


  for (map<const char*, int>::iterator begin = m.begin(); begin != m.end(); begin++) {
      // How can I get the loop sequence same as my insert sequence.
      // c, b, a, d
      std::cout << begin->first << std::endl;
  }

  getchar();
}
Run Code Online (Sandbox Code Playgroud)

c++ stl

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

Unicode 支持的 isdigit 和 isspace 函数

我有以下代码。

// mfc.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "mfc.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

#include <cctype>
#include <string>
#include <sstream>
#include <tchar.h>
#include <iostream>
#include <Strsafe.h>
#include <algorithm>
#include <cmath>
#include <limits>
#include <functional>
#include <cassert>

std::wstring toStringWithoutNumerical(const std::wstring& str) {
    std::wstring result;

    bool alreadyAppendSpace = false;
    for (int i = 0, length = str.length(); i < length; i++) {
        const TCHAR c = str.at(i);
        if (isdigit(c)) {
            continue;
        }
        if …
Run Code Online (Sandbox Code Playgroud)

c++ unicode

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

初始化静态最终变量

我想知道,有什么不同,在各种方法初始化静态最终变量?

private static final int i = 100;
Run Code Online (Sandbox Code Playgroud)

要么

private static final int i;
static {
    i = 100;
}
Run Code Online (Sandbox Code Playgroud)

这两者有什么不同吗?

java

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

十进制格式的模式

我想翻译10000000.0PREFIX10,000,000.00

我可以知道我应该将哪种模式传递给DecimalFormat?

NumberFormat numberFormat = new DecimalFormat(...);
numberFormat.format(10000000.0);
Run Code Online (Sandbox Code Playgroud)

java

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

xstream - 以UTF-8保存XML的正确方法

以前,要通过xstream 读取 UTF-8编码的XML,我使用DomDriver如下:

XStream xStream = new XStream(new DomDriver("UTF-8"));
Run Code Online (Sandbox Code Playgroud)

但是,后来我意识到这非常慢.我使用以下方式:

优化xstream的加载速度

这至少可以正常工作.

但是,后来我意识到同样的技术不能应用于编写XML.我会得到所有??? 字符.

这是在写入期间使用DomDriver的最后一个可行代码

public static boolean toXML(Object object, File file) {
    XStream xStream = new XStream(new DomDriver("UTF-8"));
    OutputStream outputStream = null;

    try {
        outputStream = new FileOutputStream(file);
        xStream.toXML(object, outputStream);
    }
    catch (Exception exp) {
        log.error(null, exp);
        return false;
    }
    finally {
        if (false == close(outputStream)) {
            return false;
        }
        outputStream = null;
    }

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

上面的代码工作正常.为了与不使用DomDriver 的read方法匹配,我将代码更改为

public static boolean toXML(Object object, File …
Run Code Online (Sandbox Code Playgroud)

java xml xstream

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

将变量传递给Mako模板

在Perl中,通过使用Template Toolkit,我就是这么做的

Perl的

my $vars = {
    name     => 'Count Edward van Halen',
};

$tt->process('letters/overdrawn', $vars)
    || die $tt->error(), "\n";
Run Code Online (Sandbox Code Playgroud)

HTML

Dear [% name %],
Run Code Online (Sandbox Code Playgroud)

Mako模板中,我该怎么办?通过他们的render功能检查,没有得到太多提示.

python mako

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

标签 统计

c++ ×6

java ×4

mako ×1

python ×1

stl ×1

unicode ×1

xml ×1

xstream ×1