鍍金池/ 問答/ C++問答
夕顏 回答

ISO C 標(biāo)準(zhǔn)中寫到

6.3.1.3 Signed and unsigned integers

When a value with integer type is converted to another integer type
other than _Bool, if the value can be represented by the new type, it
is unchanged. Otherwise, if the new type is unsigned, the value is
converted by repeatedly adding or subtracting one more than the
maximum value that can be represented in the new type until the value
is in the range of the new type. Otherwise, the new type is signed and
the value cannot be represented in it; either the result is
implementation-defined or an implementation-defined signal is raised.

換句話說,unsigned char 的表示范圍是 [0, 255],不能表示 -1,于是將 -1 加上 256 得到 255。

如果是把 signed char 型 -1 轉(zhuǎn)成 unsigned int,則用 -1 加上 4294967296 得到 4294967295。

對硬件來說,從有符號到無符號的轉(zhuǎn)換就是簡單地在前面補符號位或者直接截斷。

玄鳥 回答

以前沒有遇到過這個問題,我實驗了一下,覺得原因應(yīng)該是:

  1. 父級容器上設(shè)置overflow、overflow-y和overflow-x屬性不為visible時,會觸發(fā)一次容器寬高計算并裁剪
  2. box-shadow屬性不會影響元素的寬高,所以被overflow忽略,然后裁剪
  3. 由于設(shè)置了overflow,父級元素觸發(fā)BFC,沒有上外邊距合并,所以能夠顯示上邊的box-shadow

事實上,overflow不為visible與觸發(fā)BFC的條件很像,但不清楚是不是BFC的原因。

以上都是在chrome瀏覽器中發(fā)現(xiàn)的情況,因此可以試試上面兩位的解決方法。

但是

但是,如果你是在IE9瀏覽器中,那么僅僅是1px的margin是沒有辦法完整顯示box-shadow的,至少得是2px。

吢涼 回答

new是再堆上開內(nèi)存,除非整個進程結(jié)束,這時候會被操作系統(tǒng)回收,不然的話函數(shù)結(jié)束后內(nèi)存里的變量還在的

懶豬 回答

Remarks

The color format of the bitmap created by the CreateCompatibleBitmap function matches the color format of the device identified by the hdc parameter. This bitmap can be selected into any memory device context that is compatible with the original device.
Because memory device contexts allow both color and monochrome bitmaps, the format of the bitmap returned by the CreateCompatibleBitmap function differs when the specified device context is a memory device context. However, a compatible bitmap that was created for a nonmemory device context always possesses the same color format and uses the same color palette as the specified device context.
Note: When a memory device context is created, it initially has a 1-by-1 monochrome bitmap selected into it. If this memory device context is used in CreateCompatibleBitmap, the bitmap that is created is a monochrome bitmap. To create a color bitmap, use the HDC that was used to create the memory device context

MSDN 里說了CreateCompatibleBitmap創(chuàng)建的是monochrome(單色的)

耍太極 回答

PYTHON

lala = [1,1,1,2,3,4,5,8,10,22,24,25,26,66]
res = []
tmp = [lala[0]]
for i in range(1, lala.__len__()):
    if lala[i] - lala[i-1] == 1:
        tmp.append(lala[i])
    else:
        if len(tmp) == 1:
            res.append(tmp[0])
            tmp = [lala[i]]
        else:
            res.append(tmp)
            tmp = [lala[i]]

print(res)
荒城 回答

輸出整數(shù)的時候,%.n表示最少顯示n位數(shù)字。

枕頭人 回答

在 C++ 中,除了 ASCII 字符外的字符為寬字符,需要使用 L 標(biāo)識。而寬字符流有特定的輸出流,為 std::wcout。所以,正確的輸出方式為 std::wcout << L"你好" << std::endl。

另外,還需要涉及到 std::locale 的概念。std::locale 代表地域各個設(shè)定的集合。locale 文檔

每個輸入輸出流可以與一個 std::locale 進行綁定,默認(rèn)綁定為 std::locale("C")。此處使用 std::wcout.imbue( locale ),需要設(shè)定的地域為 zh-cn,我沒有查到相關(guān)的內(nèi)容,這個地域字符串可能跟環(huán)境有關(guān)系。

最終代碼為:

#include <cstdio>
#include <locale>
#include <string>
#include <iostream>

int main() {
    auto old_locale = std::wcout.imbue(std::locale("zh-cn"));
    std::wcout << L"你好" << std::endl;

    std::cout << "old locale: " << old_locale.name() << std::endl;
    auto new_locale = std::wcout.imbue(old_locale);
    std::cout << "new locale: " << new_locale.name() << std::endl;

    printf("你好\n");

    system("pause");
}

輸出為:

你好
old locale: C
new locale: zh-cn
你好

這部分內(nèi)容較繁雜,我也沒有很了解,希望能對你有幫助。

凝雅 回答

大致上跟其它編譯到機器碼的語言一樣:別人只能看匯編了。

不過,「故考慮把核心部分換語言重構(gòu)」,如果你考慮在同一進程里同時使用 Go 和另一種語言,特別是解釋型語言的話,還是放棄吧。Go 和 C 之間的調(diào)用已經(jīng)被 Go 核心開發(fā)者警告了(請搜索「cgo is not go」;你沒看到 Go 語言的項目都是自個兒干活,極少有混編的情況),和其它大運行時的程序調(diào)……你饒了你自己吧。

出于代碼保護目的,建議使用 Rust,和 Python、Ruby、Lua、NodeJS、Haskell、C、C++ 等等語言相互調(diào)用都容易得多。

局外人 回答

動態(tài)鏈接的地址是在運行時確定的,因此編譯連接階段不需要用到動態(tài)鏈接庫中函數(shù)的地址。之所以需要在編譯連接階段引入動態(tài)鏈接庫,主要是為了確定要連接的符號名,這樣才能在運行時根據(jù)符號名找到對應(yīng)的函數(shù)入口。

吃藕丑 回答

<?php

public function b($arr = array()) {
    if (!empty($arr)) {
        return "";
    } else {
        foreach ($arr as &$v) {
            if (is_array($v)) {
                $v = $this->b($v);
            } else {
                $v = $v + 1;
            }
        }
        return $arr;
    }
}

?>

溫衫 回答

兩種情況:
1,同步函數(shù)

這個簡單,順序執(zhí)行就可以了

2,異步函數(shù)(我猜你是這種情況)async await可以解決

async function a() {
    return Promise.resolve("a");
}
async function b() {
    return Promise.resolve("b");
}
async function c() {
    await a();
    await b();
    console.log('執(zhí)行c')
}
c();
情殺 回答

在配置文件里面,設(shè)置代理服務(wù)器不要配置

背叛者 回答

用數(shù)組的reduce方法
let arr = [[1, 2], [3, 4], [5, 6]]
let list = []
arr.reduce((pre, current, index, arr) => {

list = []
for (let i = 0; i < pre.length; i++) {
    for (let j = 0; j < current.length; j++) {
        list.push(+(pre[i] + '' + current[j]))
    }
}
return list

})

console.log(list)

逗婦惱 回答

https://www.cnblogs.com/yingp...
這個有個JAVA代碼,你可以參考下。我一開始是用C寫的,感覺太麻煩了,JAVA不太會,但是看懂了一點,希望可以幫到你

玩控 回答

其實這個問題,很簡單,分析一下就知道了。分析如下:

var str = "我是/@小王@\\和/@小李@\\的好朋友"

你要轉(zhuǎn)成

  var arr = [{"text": "我是"}, {"name": 小王"}, {"text": "和"}, {"name": "小李"}, {"text": "的好朋友"}]

以我看來就是,通過/@和@\把字符串分割,并且以/@結(jié)尾的放到text屬性中,以@\結(jié)尾的放到name中,并且保持原有順序。
既然是有兩個分割字符,那么我們就分割兩次。我簡單寫了一下,但是沒有做太多檢驗和判斷?;仡^你對參數(shù)做下校驗。

我的代碼如下:

var str = "我是/@小王@\\和/@小李@\\的好朋友";
    var strs = str.split("/@");
    var arr = new Array();
    for (var i = 0 ;i < strs.length;i++)
    {
        if(strs[i].indexOf('@\\') != -1)
        {
            var temps = strs[i].split('@\\');
            for(var j=0;j<temps.length;j++)
            {
                if(j == temps.length -1)
                {
                    var text =
                    {
                        text:temps[j]
                    }
                }else
                {
                    var name =
                    {
                        name:temps[j]
                    }
                }
            }
        }else
        {
            var text =
            {
                text:strs[i]
            }
        }
        if(name != null && '' != name && 'undifined' != name)
        {
            arr.push(name);
        }
        if(text != null && '' != text && 'undifined' != text)
        {
            arr.push(text);
        }
    }
    console.log(arr);
那么,最后控制臺輸入如下:

圖片描述

如果沒問題,請采納,謝謝。

挽歌 回答

If the two signatures are the same, it is not possible. So, the first solution: add one more tag in parameter list, like

struct Foo
{
    struct Path {};
    struct NonPath {};
    foo(std::string, Path) { /* ... */ }
    foo(std::string, NonPath) { /* ... */ }
};
int main()
{
    // ...
    auto f1 = foo(s1, Foo::Path);
    auto f2 = foo(s2, Foo::NonPath);
    return 0;
}

Of course, you can also create two different Classes.

The two solutions above will be subtle if you have more constructors. Best practice is
Named Constructor Idiom:

struct Foo
{
private:
    std::string str;
    Foo(std::string s) : str(s) {}
public:
    static Foo path(std::string s) { /* ... */ return Foo(s); }
    static Foo non_path(std::string s) { /* ... */ return Foo(s); }
};
int main()
{
    // ...
    auto f1 = Foo::path(s1);
    auto f2 = Foo::non_path(s2);
    return 0;
}
夢一場 回答

提供幾種思路:
(1)將包含 N 個數(shù)的數(shù)組打亂,然后選取前 10 個數(shù)。
(2)將每次得到的數(shù)放入 HashSet,下次取得一個數(shù)時先判斷是否存在于 Set 當(dāng)中,直到當(dāng) Set 的 size 為 10 時結(jié)束。