C++ Input Performance

I was trying to solve a problem on InterviewStreet. After some time I determine that I was actually spending the bulk of my time reading the input. This particular question had a lot of input, so that makes some amount of sense. What doesn't make sense is why the varying methods of input had such different performances: Initially I had: std::string command; std::cin >> command; R

C ++输入性能

我试图解决InterviewStreet上的一个问题。 过了一段时间后,我确定我实际上花费了大部分时间阅读输入内容。 这个特定的问题有很多输入,所以这有一定的意义。 没有道理的是,为什么不同的输入方法有不同的表现: 最初我有: std::string command; std::cin >> command; 更换它明显更快: char command[5]; cin.ignore(); cin.read(command, 5); 重写所有使用scanf使其更快 char command; scanf("get_%c", &co

Characters overlapping when they have changed color and are printed backwards

As you can see the upper dark X's are cut even though there is space for them. This happens because they have changed color and are printed backwards (from right to left). Is this a bug, faulty code, a bad setup on my system or (I doubt it) like it is supposed to be? Here is the code that generates this output: #include <Windows.h> #include <iostream> void moveTo(int x,int

当字符改变颜色并向后打印时字符重叠

正如你所看到的那样,即使有空间,上部黑色的X也会被切断。 发生这种情况是因为它们已经改变颜色并向后打印(从右到左)。 这是一个错误,错误的代码,我的系统设置不正确,或者(我怀疑它)是否应该是这样? 以下是生成此输出的代码: #include <Windows.h> #include <iostream> void moveTo(int x,int y){ COORD kord={x,y}; SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),kord); } vo

Fast resize of a mmap file

I need a copy-free re-size of a very large mmap file while still allowing concurrent access to reader threads. The simple way is to use two MAP_SHARED mappings (grow the file, then create a second mapping that includes the grown region) in the same process over the same file and then unmap the old mapping once all readers that could access it are finished. However, I am curious if the scheme b

快速调整mmap文件的大小

我需要一个非复制的非常大的mmap文件的重新大小,同时仍然允许并发访问读者线程。 最简单的方法是在相同的文件上使用两个MAP_SHARED映射(增长文件,然后创建包含增长区域的第二个映射),然后在所有可以访问它的读取器完成后取消映射旧映射。 但是,我很好奇下面的方案是否可行,如果是的话,它是否有优势。 使用MAP_PRIVATE映射文件 在多个线程中对该内存执行只读访问 要么获得文件的互斥锁,要写入内存(假设这是通

c++

Recently I have started studying about memory leaks in C++, so I may ask a naive questions. I have a c++ library that is using OpenSSL - my task is to check if there are memory leaks in this lib. I have run Visual Leak Detector to check mem leaks. I see that the calls to SSL_library_init(); and SSL_load_error_strings(); are leading leak - quick googling is showing that at the end of usage

C ++

最近我开始研究C ++中的内存泄漏问题,所以我可能会问一个天真的问题。 我有一个使用OpenSSL的c ++库 - 我的任务是检查这个库中是否有内存泄漏。 我运行了Visual Leak Detector来检查内存泄漏。 我看到对SSL_library_init();的调用SSL_library_init(); 和SSL_load_error_strings(); 是领先的漏洞 - 快速Google搜索显示,在使用结束时,我必须打电话给以下人员: CONF_modules_free(); ERR_remove_state(0); ENGINE_cleanu

copying constness in templates fails strangely based on type

I wrote a template to copy constness of a pointer argument for C++11: template<typename S, typename D> struct copy_const { typedef typename std::conditional<std::is_const<S>::value, typename std::add_const<D>::type, typename std::remove_const<D>::type>::type type; }; To be used in a method like this: template<typename T, typename U,

在模板中复制常量会基于类型奇怪地失败

我写了一个模板来复制C ++ 11的指针参数的常量: template<typename S, typename D> struct copy_const { typedef typename std::conditional<std::is_const<S>::value, typename std::add_const<D>::type, typename std::remove_const<D>::type>::type type; }; 要在这样的方法中使用: template<typename T, typename U, class=typename std::enable_if<st

Error c2664 in VS 2013 C++

So, I have a class called "music" and when I try to compile the code, it gives me the following errors: Error 13 error C2664: 'music::music(const music &)' : cannot convert argument 2 from 'const char [5]' to 'char' c:usersandrei bordeianudocumentsvisual studio 2013projectsmediaplusmediaplussource.cpp 362 1 MediaPlus 14 IntelliSense: no instance of constr

VS 2013 C ++中的错误c2664

所以,我有一个名为“音乐”的类,当我尝试编译代码时,它给了我以下错误: 错误13错误C2664:'music :: music(const music&)':无法将参数2从'const char [5]'转换为'char'c: users andrei bordeianu documents visual studio 2013 projects mediaplus mediaplus source.cpp 362 1 MediaPlus 14智能感知:没有构造函数“music :: music”的实例匹配参数列表参数类型是:(const char [5],c

Template function giving compilation error

Possible Duplicate: std::map::const_iterator template compilation error The idea is to create a function which takes the container type as a Template parameter. Since maps have to summed up differently compared to other sequential containers I overloaded the Sum function for the map as shown below. This is the function which is giving me errors: template<typename T1, typename T2> do

模板函数给出编译错误

可能重复: std :: map :: const_iterator模板编译错误 这个想法是创建一个将容器类型作为Template参数的函数。 由于地图必须与其他顺序容器相比总结不同,因此我重载了地图的Sum函数,如下所示。 这是给我错误的功能: template<typename T1, typename T2> double Sum(const map<T1,T2>& input) { double finalSum=0; map<T1,T2>::const_iterator iter_begin=input.begin(); map<T1,T2>::co

const TypedeffedIntPointer not equal to const int *

I have the following C++ code: typedef int* IntPtr; const int* cip = new int; const IntPtr ctip4 = cip; I compile this with Visual Studio 2008 and get the following error: error C2440: 'initializing' : cannot convert from 'const int *' to 'const IntPtr' Clearly my understanding of typedefs is not what is should be. The reason I'm asking, I'm storing a point

const TypedeffedIntPointer不等于const int *

我有以下C ++代码: typedef int* IntPtr; const int* cip = new int; const IntPtr ctip4 = cip; 我用Visual Studio 2008进行编译,并得到以下错误: 错误C2440:'初始化':不能从'const int *'转换为'const IntPtr' 显然,我对typedef的理解不是应该的。 我问的原因是,我在STL地图中存储了一个指针类型。 我有一个函数返回一个我想用来在地图中搜索的常量指针(使用map :: find(const key_

Template instantiation error

I have template function "compare" defined as below. #include<iostream> using namespace std; template<typename T> void compare(const T&a, const T& b) { cout<<"Inside compare"<<endl; } main() { compare("aa","bb"); compare("aa","bbbb"); } When i instantiate compare with string literals of same length, the compiler doesnot complain. When i do it wit

模板实例化错误

我有如下定义的模板函数“比较”。 #include<iostream> using namespace std; template<typename T> void compare(const T&a, const T& b) { cout<<"Inside compare"<<endl; } main() { compare("aa","bb"); compare("aa","bbbb"); } 当我实例化与相同长度的字符串文字比较时,编译器不会抱怨。 当我用不同长度的文字做它时,它说“错误:没有用于比较调用的匹配函数(const char [3],co

A library to convert svg to images?

I am looking for a library written either in C or C++ which can convert the svg to image formats. I came across inkscape which converts svg to images. but to use this I must run inkscape as a process and this not the solution I am after. I need the library to run on both Windows and Linux as well. I am after a C or C++ library. If it was with Java I would have used Apache's Batik rast

将svg转换为图像的库?

我正在寻找以C或C ++编写的库,可以将svg转换为图像格式。 我遇到了将svg转换为图像的inkscape。 但为了使用它,我必须将Inkscape作为一个流程运行,而这不是我所追求的解决方案。 我需要该库在Windows和Linux上运行。 我在C或C ++库之后。 如果是Java,我会使用Apache的Batik光栅器。 渲染SVG的规范库是librsvg。 你可能想检查一下。 对于图像编辑,您可以使用ImageMagick,它非常流行,它支持多种类型的图像。 我