我已经看到在Quora上将参考变量声明为C++中的常量.
static constexpr const int& r = 3;
Run Code Online (Sandbox Code Playgroud)
那么,为什么都constexpr和const在单个语句中使用?
这种陈述的目的是什么?
C #pragma和_Pragma()C 之间有什么区别?
句法:
#pragma arg
Run Code Online (Sandbox Code Playgroud)
和
_Pragma(arg)
Run Code Online (Sandbox Code Playgroud)
我应该什么时候使用_Pragma(arg)?
我想在我的 c++ 项目中使用zlib库。所以,我已经下载了zlib库(zlib_1_2_8_msvc2015_64.zip)。然后,我在"C:\Program Files\Zlib". 然后,将zlib_1_2_8_msvc2015_64.zip文件解压缩到"C:\Program Files\Zlib".
之后,我打开了Visual Studio 2017并转到属性=> C/C++ =>常规=>附加包含目录并添加了该路径:"C:\Program Files\Zlib\msvc2015_64"。
之后,我#include <zlib.h>在我的项目中添加了头文件。但是,不工作。
那么,如何在 Visual Studio 2017 中使用 zlib 库?
我试图阅读mozilla.rsa文件并使用C++解析插件ID.
我的努力:
std::string rsaPath = xpiDir + "\\META-INF\\mozilla.rsa";
int rets = system(("CertUtil " + rsaPath + " | findstr " + "S=CA").c_str());
//
.....
My additional logic.............
.....
///
Run Code Online (Sandbox Code Playgroud)
它在Windows 7及更高版本上运行良好.但是,在Windows XP上没有.
有没有办法使用C或C++ 从mozilla.rsa文件中读取插件ID ?
我是Python新手。我有一个三个变量x, y,z作为int. 我比较了if条件中的三个变量。我对以下代码结果感到困惑。
该表达式的x < y <= z计算结果为 false。
让我们假设x = 10、y = 5和z = 0。如果x < y变为False,则False <= 0变为True。但输出为False。为什么?
我的Python脚本:
#!/usr/bin/python
x = 10
y = 5
z = 0
if (x < y < z):
print"True"
else:
print"False"
Run Code Online (Sandbox Code Playgroud) 如果我像这样使用指针mutable:const
class Test
{
public:
mutable const int* ptr; // OK
};
Run Code Online (Sandbox Code Playgroud)
运行良好。
但是,如果我这样使用:
class Test
{
public:
mutable int * const ptr; // Error
};
Run Code Online (Sandbox Code Playgroud)
一个错误 :
prog.cpp:6:25: error: const 'ptr' cannot be declared 'mutable'
mutable int * const ptr;
^
prog.cpp: In function 'int main()':
prog.cpp:11:7: error: use of deleted function 'Test::Test()'
Test t;
^
prog.cpp:3:7: note: 'Test::Test()' is implicitly deleted because the default definition would be ill-formed:
class Test
^
prog.cpp:3:7: error: uninitialized const …Run Code Online (Sandbox Code Playgroud) 在以下程序中,ptr指向未初始化的变量x.在打印之前ptr,我已经分配10给ptr和打印.
#include <stdio.h>
int main()
{
int *ptr;
int x;
ptr = &x;
*ptr = 10;
printf(" x = %d\n", x);
printf(" *ptr = %d\n", *ptr);
}
Run Code Online (Sandbox Code Playgroud)
双方ptr并x打印正确的值.但是,我怀疑,是否定义了行为?
我使用此参考读了C中的动态内存分配.
那个文件Say's:
realloc()只应用于动态分配的内存.如果未动态分配内存,则行为未定义.
如果我们使用realloc()这样的东西:
int main()
{
int *ptr;
int *ptr_new = (int *)realloc(ptr, sizeof(int));
return 0;
}
Run Code Online (Sandbox Code Playgroud)
根据该引用,该程序未定义,因为指针ptr未动态分配.
但是,如果我使用类似的东西:
int main()
{
int *ptr = NULL;
int *ptr_new = (int *)realloc(ptr, sizeof(int));
return 0;
}
Run Code Online (Sandbox Code Playgroud)
根据该参考,它是否也是未定义的行为?
我的第二种情况不会调用未定义的行为.我对吗?
我试图理解C++中的存储类说明符.我有两个案子.
这里,在给定的相同范围内,声明相同的变量名称.
情况1:
#include <iostream>
static int i;
extern int i;
int main() {
std::cout<<i<<std::endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
输出:
0
Run Code Online (Sandbox Code Playgroud)
案例2:
#include <iostream>
extern int i;
static int i;
int main() {
std::cout<<i<<std::endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
得到错误:
prog.cpp:4:12: error: 'i' was declared 'extern' and later 'static' [-fpermissive]
static int i;
^
prog.cpp:3:12: note: previous declaration of 'i'
extern int i;
Run Code Online (Sandbox Code Playgroud)
为什么第一种情况正常,而第二种情况却出错?