小编san*_*ser的帖子

在 GitHub CLI 中切换用户

我正在使用 GitHub CLI 和MinGit for Windows

当我注销 GitHub CLI 并gh auth logout通过调用 git 使用不同的帐户重新登录时,gh auth login配置不会更改。

当我输入时,条目git config --global --list仍然指向旧帐户。因此,当我提交时,看起来提交是由我的旧帐户进行的。user.nameuser.email

我知道我可以输入git config --global user.name "username"并更改名称,但如何使用 GitHub CLI 正确执行此操作?

如果我无法使用 GitHub CLI 执行此操作,我需要user.name更改user.email的唯一两个条目才能作为我的新帐户提交?

git windows-10 github-cli

7
推荐指数
2
解决办法
5266
查看次数

如何在 Visual Studio 2019 中使用 editorconfig?

.editorconfig在 VS 2019 中使用以下设置在解决方案级别创建了文件:

root = true

# All files
[*]
indent_style = tab
indent_size = 4
tab_width = 4
Run Code Online (Sandbox Code Playgroud)

然后我重新启动了 IDE,以使更改生效。但是,只有.editorconfig文件本身使用选定的设置。我的解决方案中的所有其他文件仍然使用空格而不是配置中定义的设置。

然后我将.editorconfig文件放在项目级别并再次重新启动。没变。

如何正确使用.editorconfig文件以便我的所有项目文件都使用其中定义的设置?

注意:我使用的是最新版本的 VS 2019 Community。

editorconfig visual-studio-2019

6
推荐指数
1
解决办法
5903
查看次数

如何正确设置_MSVC_LANG值?

您可能知道_MSVC_VALUE,确定是否设置宏_HAS_CXX17_HAS_CXX20今天我尝试在Visual Studio 2019(最新16.6.4版本)中编译以下代码:

#include <algorithm>
#include <execution>
#include <vector>

int main()
{
    std::vector<int> _vector = { 3, 2, 1 };
    std::sort(std::execution::par, _vector.begin(), _vector.end());
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

不幸的是,它会抛出错误。例如这个: C3083 'execution': the symbol to the left of a '::' must be a type

当我查看<execution>头文件时,我注意到它无法编译,因为宏_HAS_CXX17设置为 0。

#if !_HAS_CXX17
#pragma message("The contents of <execution> are available only with C++17 or later.")
#else // ^^^ !_HAS_CXX17 / _HAS_CXX17 vvv
Run Code Online (Sandbox Code Playgroud)

然后我查看了vcruntime.h_HAS_CXX17文件中宏的定义:

#if !defined(_HAS_CXX17) && …
Run Code Online (Sandbox Code Playgroud)

c++ visual-c++ c++17 visual-studio-2019

5
推荐指数
1
解决办法
2685
查看次数

打印模板参数列表中类型的 typeid

我想定义一个函数,在其模板参数列表中打印类型的 typeid 名称。该函数不接受任何值参数。因此,例如调用print<int>()应该打印intprint<int, double>()应该打印int, double并且调用print<>()应该输出字符串no types

我有一个可行的解决方案,但是它使用了额外的方法来执行此操作,如以下答案vector所示:

#include <iostream>
#include <vector>

template<class... T>
void print() {
    std::vector<const char*> ids{ typeid(T).name()... };

    if (ids.empty()) {
        std::cout << "no types\n";
        return;
    }

    const auto last = ids.size() - 1;

    for (size_t i = 0; i < last; i++)
        std::cout << ids[i] << ", ";

    std::cout << ids[last] << '\n';
}

int main() {
    print<>();
    print<int, double, char>(); …
Run Code Online (Sandbox Code Playgroud)

c++ templates fold-expression c++17

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

地址清理程序未找到丢失的删除语句

我已在 Visual Studio 中为我的项目启用了 Address Sanitizer,并成功使用Microsoft Learn中的以下代码对其进行了测试。

#include <stdio.h>

int x[100];

int main() {
    printf("Hello!\n");
    x[100] = 5; // Boom!
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

但是,清理程序无法在以下代码中找到丢失的删除语句:

struct Object {
    int x;
    int y;
};

int main() {
    Object* obj = new Object();
    // Boom!
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

查看生成的程序集,我们可以看到 new 运算符确实被调用并且没有被优化掉。以下输出取自 Debug/x86 配置,但对于配置 Debug/x64、Release/x86 和 Release/x64 可以获得类似的输出。

; 6    : int main() {

    push    ebp
    mov ebp, esp
    sub esp, 12                 ; 0000000cH
    mov ecx, OFFSET __62A33F1D_Source@cpp
    call    @__CheckForDebuggerJustMyCode@4

; 7    : …
Run Code Online (Sandbox Code Playgroud)

c++ visual-c++ address-sanitizer visual-studio-2022

0
推荐指数
1
解决办法
273
查看次数