我正在使用getenv("TEMP"),但我收到警告告诉我使用_dupenv_s.
我在网上找不到_dupenv_s的例子.
文档内容如下:
errno_t _dupenv_s(
char **buffer,
size_t *numberOfElements,
const char *varname
);
Run Code Online (Sandbox Code Playgroud)
但他们指的是什么缓冲?我只有varname.避免使用缓冲区不是更好吗?
我正在研究c ++如何通过汇编语言调用正确的成员函数.我带来的简单程序如下:
class A
{
public:
virtual void show() {}
};
class B : public A
{
public:
void show() {}
};
int main()
{
A* pA = new B;
pA->show();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
其装配如下:
main:
.LFB2:
.cfi_startproc
.cfi_personality 0x3,__gxx_personality_v0
pushq %rbp
.cfi_def_cfa_offset 16
movq %rsp, %rbp
.cfi_offset 6, -16
.cfi_def_cfa_register 6
pushq %rbx
subq $24, %rsp
movl $8, %edi
.cfi_offset 3, -24
call _Znwm <<<================ 1
movq %rax, %rbx
movq %rbx, %rax
movq %rax, %rdi
call _ZN1BC1Ev
.L11:
movq …Run Code Online (Sandbox Code Playgroud) 既然微软已经在Windows 10的文件系统中恢复了OneDrive(假设它们在6个月内没有再丢弃它),我正在寻找如何确定任意文件的同步状态.
资源管理器中至少显示五种不同的状态(这正是我观察到的,可能还有其他状态):
对于文件,可以使用该FILE_ATTRIBUTE_OFFLINE属性确定前两个状态.
似乎可以使用新的未记录的文件属性为文件确定"始终可用"状态0x00080000.
然而,确定文件夹的这些状态以及文件和文件夹的同步和错误状态仍然是个谜.
我的第一个想法是使用属性system(IPropertyStore),但以下四个属性键都没有帮助:
PKEY_OfflineAvailability 回报 VT_EMPTYPKEY_OfflineStatus 回报 VT_EMPTYPKEY_FilePlaceholderStatus 返回一个未记录的值(0xe)但它在状态确实时不会改变PKEY_FileOfflineAvailabilityStatus 回报 VT_EMPTY我有一种感觉,这将是另一个未记录的Microsoft API,但我想我会问是否有人有任何建议.
我目前正在将一个相当大的项目从VS 2008转换到2012年,并且遇到了一个问题,即条件运算符类型转换的执行方式发生了变化.
首先让我说我接受条件运算符的语义有点复杂,并且意识到代码原来做的可能不正确,但我真的很困惑现在在VS 2012中发生的事情,我想知道是否有人可以解释为什么它做它做的事情.
class DummyString
{
wchar_t wchBuf[32];
public:
DummyString() { *wchBuf = 0; }
DummyString(int) { *wchBuf = 0; }
DummyString(const DummyString& ds) { *wchBuf = 0; }
operator const wchar_t*() const { return wchBuf; }
};
int _tmain(int argc, _TCHAR* argv[])
{
DummyString ds;
// note: the argc test is simply to stop the conditional operator
// being optimised away
const wchar_t* pPtr = (argc == 100) ? 0 : ds;
assert(pPtr == static_cast<const wchar_t*>(ds));
return 0; …Run Code Online (Sandbox Code Playgroud) 我得到了一些格式不正确的代码,如下所示,但它是使用 MSVC 19.32.31329 和 /std:c++latest 构建的。
#include <Windows.h>
template<typename T>
void foo() {
int i;
// Can be anything that looks like a function call
baz(i.str());
}
int WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
int i;
// The following line is wrong because i has an integral type
// and doesn't have .str().
i.str();
}
Run Code Online (Sandbox Code Playgroud)
该代码显然是错误的,不应该编译,但它确实可以编译。这是编译器错误吗?
我使用std::multimap::equal_range()和遇到了以下问题insert().
根据cplusplus.com和cppreference.com,std::multimap::insert不会使任何迭代器无效,但以下代码会导致无限循环:
#include <iostream>
#include <map>
#include <string>
int main(int argc, char* argv[])
{
std::multimap<std::string,int> testMap;
testMap.insert(std::pair<std::string,int>("a", 1));
testMap.insert(std::pair<std::string,int>("a", 2));
testMap.insert(std::pair<std::string,int>("a", 3));
auto range = testMap.equal_range(std::string("a"));
for (auto it = range.first; it != range.second; ++it)
{
testMap.insert(std::pair<std::string,int>("b", it->second));
// this loop becomes infinite
}
// never gets here
for (auto it = testMap.begin(); it != testMap.end(); ++it)
{
std::cout << it->first << " - " << it->second << std::endl;
} …Run Code Online (Sandbox Code Playgroud) 通用Lambda是一种定义lambdas的方法,其内容如下:
auto identity = [](auto a){return a;}
Run Code Online (Sandbox Code Playgroud)
比较这个:
template <typename T>
T Identity(T t){return t;}
Run Code Online (Sandbox Code Playgroud)
或者
template <typename T>
struct Identity { T operator()(T a) { return a; } };
Run Code Online (Sandbox Code Playgroud)
这是我的理解
lambdas允许使用[&],[=]等进行上下文捕获,我不确定如何在通用lambda中使用/应用它.这是主要区别吗?
通用lambdas可以转换为函数指针,而模板特化可以转换为函数指针.
一个简单的现实世界示例将有助于了解使用什么和何时使用.
[附加]以下是通用的lambda提案:http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3559.pdf
我想我已经对此进行了充分的研究,但没有找到可接受的答案。首先是大招:Windows 8.1,Visual Studio2013。尽管如此,我认为这些都不重要。
问题如下。我正在编写的应用程序使用A.dll。我们使用第三方供应商产品(备份程序,但这并不重要),该产品已在HKEY_CLASSES_ROOT \ Directory \ shellex \ ContextMenuHandlers下安装了上下文菜单处理程序控件。假设它的路径是c:\ Program Files \ Vendor \ control.dll。
现在的问题是,当我的程序打开一个文件选择器对话框时(这是一个使用QFileDialog的Qt程序,然后使用标准的Windows),该控件被加载以提供上下文相关的右键单击功能。此控件取决于“ A.dll”的不同版本,并且在加载control.dll时,我的程序立即崩溃。
我不需要这个额外的功能。我想做的是防止在我的进程中加载此特定的dll(control.dll)。在面向对象的世界中,我将简单地重载LoadLibrary(),检查该特定的DLL,然后以其他方式调用标准的DLL。但是,这似乎不可行。
是否有捷径可寻?
谢谢!担
我有一个C++ 11程序,它配置了许多可运行的对象,将它们放在一个std::vector,然后在不同的线程中启动它们.不幸的是,当我迭代向量中的对象时,我只是为最后一个对象启动了线程.我已经在以下测试代码中将问题提炼到了核心(在OSX 10.9.5上clang++ -std=c++11 cpp_threadlaunch.cpp使用clang6.0 编译).
#include <iostream>
#include <thread>
#include <vector>
#include <unistd.h>
std::mutex outputlock;
class agent {
public:
agent(std::string name) : m_name(name) {};
~agent(void) {};
void run(void) {
while (1) {
outputlock.lock();
std::cout << "Agent: " << m_name << std::endl;
outputlock.unlock();
sleep(1);
}
}
std::string getName(void) { return m_name; }
private:
std::string m_name;
};
int main()
{
std::vector<std::thread> threads;
std::vector<agent*> agents;
// std::string goal = "succeed";
std::string goal = "fail";
agents.push_back(new agent("A")); …Run Code Online (Sandbox Code Playgroud) 在C++中,我从未见过像以下行#import那样导入的.exe行:
#import "C:\Program Files\Google\Google Earth\googleearth.exe"
Run Code Online (Sandbox Code Playgroud)
这条线做了什么以及如何理解/理解它?