我想找到检查文件是否存在于标准C++ 11,C++或C中的最快方法.我有数千个文件,在对它们做一些事情之前我需要检查它们是否全部存在.我可以写什么而不是/* SOMETHING */以下功能?
inline bool exist(const std::string& name)
{
/* SOMETHING */
}
Run Code Online (Sandbox Code Playgroud) 我有一个semilogx情节,我想删除xticks.我试过了:
plt.gca().set_xticks([])
plt.xticks([])
ax.set_xticks([])
Run Code Online (Sandbox Code Playgroud)
网格消失(确定),但小蜱(在主蜱的位置)仍然存在.如何删除它们?
假设我们有一个T myarray[100]带有T = int,unsigned int,long long int或unsigned long long int,将所有内容重置为零的最快方法是什么(不仅用于初始化,而且在我的程序中多次重置内容) ?也许有memset?
像动态数组一样的问题T *myarray = new T[100].
使用C++ 11 std::array,我是否可以保证语法std::array<T, N> x;将默认初始化数组的所有元素?
编辑:如果没有,是否有一个语法可以在所有数组(包括零大小的数组)上工作,以将所有元素初始化为默认值?
编辑:在cppreference上,默认的构造函数描述说:
(constructor) (implicitly declared) (public member function)
default-constructs or copy-constructs every element of the array
Run Code Online (Sandbox Code Playgroud)
所以答案可能是肯定的.但我想根据标准或未来标准确定这一点.
考虑以下内联函数:
// Inline specifier version
#include<iostream>
#include<cstdlib>
inline int f(const int x);
inline int f(const int x)
{
return 2*x;
}
int main(int argc, char* argv[])
{
return f(std::atoi(argv[1]));
}
Run Code Online (Sandbox Code Playgroud)
和constexpr等效版本:
// Constexpr specifier version
#include<iostream>
#include<cstdlib>
constexpr int f(const int x);
constexpr int f(const int x)
{
return 2*x;
}
int main(int argc, char* argv[])
{
return f(std::atoi(argv[1]));
}
Run Code Online (Sandbox Code Playgroud)
我的问题是:说明constexpr符是否意味着说明inline符,如果一个非常量参数传递给一个constexpr函数,编译器将尝试inline该函数,就像说明inline符被放入其声明一样?
C++ 11标准能保证吗?
std::system_clock和之间有什么区别std::steady_clock?(说明不同结果/行为的示例案例会很棒).
如果我的目标是精确测量的功能(如基准)的执行时间,这将是之间是最好的选择std::system_clock,std::steady_clock和std::high_resolution_clock?
我用matplotlib搜索如何用尽可能少的指令绘制一些东西,但我在文档中找不到任何帮助.
我想绘制以下内容:
怎么做?
我想知道是否
std::is_unsigned<bool>::value
Run Code Online (Sandbox Code Playgroud)
根据标准是否明确定义?
我问这个问题因为typename std::make_unsigned<bool>::type没有明确定义.
我测试了两种写入配置:
1)Fstream缓冲:
// Initialization
const unsigned int length = 8192;
char buffer[length];
std::ofstream stream;
stream.rdbuf()->pubsetbuf(buffer, length);
stream.open("test.dat", std::ios::binary | std::ios::trunc)
// To write I use :
stream.write(reinterpret_cast<char*>(&x), sizeof(x));
Run Code Online (Sandbox Code Playgroud)
2)手动缓冲:
// Initialization
const unsigned int length = 8192;
char buffer[length];
std::ofstream stream("test.dat", std::ios::binary | std::ios::trunc);
// Then I put manually the data in the buffer
// To write I use :
stream.write(buffer, length);
Run Code Online (Sandbox Code Playgroud)
我期待同样的结果......
但是我的手动缓冲可以将性能提高10倍来写入100MB的文件,并且与正常情况相比,fstream缓冲不会改变任何东西(不重新定义缓冲区).
有人对这种情况有解释吗?
编辑:这是新闻:刚刚在超级计算机上完成的基准测试(Linux 64位架构,持续英特尔至强8核,Lustre文件系统和...希望配置良好的编译器)
(我没有解释1kB手动缓冲器"共振"的原因......)
编辑2:在1024 B的共振(如果有人对此有所了解,我很感兴趣):

我有两个与CMake相关的问题
1)假设我们有一个变量${MY_CURRENT_DIR},它包含一个包含几个子目录的目录路径:mydir1,mydir2和mydir3.我想检测这些子目录并将其名称放入${SUBDIRS}(不是这些目录的完整路径,只是它们的名称).如何自动完成?
2)假设${SUBDIRS}包含"mydir1 mydir2 mydir3".如何更换
ADD_SUBDIRECTORY(mydir1)
ADD_SUBDIRECTORY(mydir2)
ADD_SUBDIRECTORY(mydir3)
Run Code Online (Sandbox Code Playgroud)
循环结束${SUBDIRS}?
非常感谢你.