小编use*_*233的帖子

非常简单的代码,并得到错误C2712,无法理解为什么

我有一段时间的麻烦error C2712: Cannot use __try in functions that require object unwinding,在缩小问题之后,我留下了一个非常非常简单的代码,我无法理解为什么它会导致这个错误.我在Windows下使用Visual Studio.

我用/ EHa编译(我不使用/ EHsc)

我使用__try/__except和不使用的原因try/catch是因为我想捕获所有错误,并且不希望程序在任何情况下崩溃,包括例如除以0,try-catch不会捕获.

#include <string>
static struct myStruct
{
    static std::string foo() {return "abc";}
};

int main ()
{
    myStruct::foo();

    __try 
    { }
    __except (true)
    { }

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

输出:

error C2712: Cannot use __try in functions that require object unwinding
Run Code Online (Sandbox Code Playgroud)

c++ visual-studio try-except

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

c ++无法获得"wcout"来打印unicode,并让"cout"工作

不能让"wcout"在多个代码页中打印unicode字符串,同时让"cout"工作

请帮我把这3行一起工作.

std::wcout<<"abc "<<L'\u240d'<<" defg "<<L'?'<<" hijk"<<std::endl;
std::cout<<"hello world from cout! \n";
std::wcout<<"hello world from wcout! \n";
Run Code Online (Sandbox Code Playgroud)

输出:

abc hello world from cout!
Run Code Online (Sandbox Code Playgroud)

我试过了:

#include <io.h> 
#include <fcntl.h>
_setmode(_fileno(stdout), _O_U8TEXT);
Run Code Online (Sandbox Code Playgroud)

问题:"cout"失败了

尝试:

std::locale mylocale("");
std::wcout.imbue(mylocale);
Run Code Online (Sandbox Code Playgroud)

和:

SetConsoleOutputCP(1251);
Run Code Online (Sandbox Code Playgroud)

setlocale(LC_ALL, "");
Run Code Online (Sandbox Code Playgroud)

SetConsoleCP(CP_UTF8)
Run Code Online (Sandbox Code Playgroud)

没有任何效果

c++ windows unicode cout utf-8

5
推荐指数
2
解决办法
3028
查看次数

如何获得卷序列号

我试图用c ++中的winapi获取卷序列号

我有以下代码:

DWORD VolumeSerialNumber=0; 
GetVolumeInformation(L"c:\\", NULL, NULL, &VolumeSerialNumber, NULL, NULL, NULL, NULL);
Run Code Online (Sandbox Code Playgroud)

它工作正常并返回,VolumeSerialNumber=571477456 但在cmd我使用时,dir我得到:

C:\Users\User>dir
 Volume in drive C is Windows
 Volume Serial Number is 2210-0DD0
Run Code Online (Sandbox Code Playgroud)

我怎么转换571477456到2210-0DD0?

c c++ winapi

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

如何在c ++中使用带有通配符的DeleteFile

如何将DeleteFile与通配符一起使用?

因此c:\myFolder\a*.txt将删除a123.txta5555.txt,但不b123.txt

c++ winapi

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

添加字符串到列表

我想得到一个清单:

'abc0'
'abc1'
'abc2'
...
'abc9'
Run Code Online (Sandbox Code Playgroud)

该命令range(10)返回0到9之间的数字列表,但是如何将字符串添加'abc'到列表中的每个元素?

python list python-2.7

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

标签 统计

c++ ×4

winapi ×2

c ×1

cout ×1

list ×1

python ×1

python-2.7 ×1

try-except ×1

unicode ×1

utf-8 ×1

visual-studio ×1

windows ×1