standard-library

“Unresolved inclusion” error with Eclipse CDT for C standard library headers

不打扰是莪最后的温柔 提交于 2019-11-26 12:05:49
问题 I set up CDT for eclipse and wrote a simple hello world C program: #include <stdio.h> int main(void){ puts(\"Hello, world.\"); return 0; } The program builds and runs correctly, but eclipse keeps showing this yellow question mark by the side of inclusion statement that says \"Unresolved inclusion: <stdio.h>\" when I put mouse over it. It doesn\'t affect running of the program but I find it rather annoying. Does anyone have any idea how to remove it ? 回答1: The compiler Eclipse is using is able

How to handle key press events in c++

故事扮演 提交于 2019-11-26 11:29:15
问题 I am writing a custom console program. And I want to make it look like an actual one. So I want to bind some actions with keypress events. For example when the up arrow is pressed previously executed commands should be shown to the user. I know about SDL. But I think that it\'s not a standard library, is it ?? If there is other alternative of it, that included in standard CPP library, please let me know. Thanks. 回答1: You won't find anything in the standard library for that. It's all Platform

What is the purpose of the div() library function?

▼魔方 西西 提交于 2019-11-26 10:02:32
问题 When C has the / operator to divide two numbers, what is the purpose of having the div() library function? Is there any scenario where / can\'t be used but div() can? 回答1: From the C99 Rationale document: (7.20.6.2 The div, ldiv, and lldiv functions) Because C89 had implementation-defined semantics for division of signed integers when negative operands were involved, div and ldiv, and lldiv in C99, were invented to provide well-specified semantics for signed integer division and remainder

Why do some built-in Python functions only have pass?

拈花ヽ惹草 提交于 2019-11-26 09:02:20
问题 I wanted to see how a math.py function was implemented, but when I opened the file in PyCharm I found that all the functions are empty and there is a simple pass . For example: def ceil(x): # real signature unknown; restored from __doc__ \"\"\" ceil(x) Return the ceiling of x as a float. This is the smallest integral value >= x. \"\"\" pass I guess it is because the functions being used are actually from the C standard library. How does it work? 回答1: PyCharm is lying to you. The source code

Why isn&#39;t `int pow(int base, int exponent)` in the standard C++ libraries?

微笑、不失礼 提交于 2019-11-26 07:25:48
问题 I feel like I must just be unable to find it. Is there any reason that the C++ pow function does not implement the \"power\" function for anything except float s and double s? I know the implementation is trivial, I just feel like I\'m doing work that should be in a standard library. A robust power function (i.e. handles overflow in some consistent, explicit way) is not fun to write. 回答1: As a matter of fact, it does. Since C++11 there is a templated implementation of pow(int, int) --- and

What is std::promise?

孤者浪人 提交于 2019-11-26 06:09:43
问题 I\'m fairly familiar with C++11\'s std::thread , std::async and std::future components (e.g. see this answer), which are straight-forward. However, I cannot quite grasp what std::promise is, what it does and in which situations it is best used. The standard document itself doesn\'t contain a whole lot of information beyond its class synopsis, and neither does just::thread. Could someone please give a brief, succinct example of a situation where an std::promise is needed and where it is the

How to flatten a list to a list without coercion?

China☆狼群 提交于 2019-11-26 04:42:20
问题 I am trying to achieve the functionality similar to unlist, with the exception that types are not coerced to a vector, but the list with preserved types is returned instead. For instance: flatten(list(NA, list(\"TRUE\", list(FALSE), 0L)) should return list(NA, \"TRUE\", FALSE, 0L) instead of c(NA, \"TRUE\", \"FALSE\", \"0\") which would be returned by unlist(list(list(NA, list(\"TRUE\", list(FALSE), 0L)) . As it is seen from the example above, the flattening should be recursive. Is there a

Template Specialization VS Function Overloading

泄露秘密 提交于 2019-11-26 01:46:50
问题 A textbook I have notes that you can provide your own implementation for standard library functions like swap(x,y) via template specialization or function overloading. This would be useful for any types which can benefit from something other than an assignment swap, like STL containers for example (which already have swaps written, I know). My questions are the following: What\'s better: template specialization to give your specialized swap implementation, or function overloading providing

Subclass/inherit standard containers? [closed]

≡放荡痞女 提交于 2019-11-25 22:48:45
问题 I often read this statements on Stack Overflow. Personally, I don\'t find any problem with this, unless I am using it in a polymorphic way; i.e. where I have to use virtual destructor. If I want to extend/add the functionality of a standard container then what is a better way than inheriting one? Wrapping those container inside a custom class requires much more effort and is still unclean. 回答1: There are a number of reasons why this a bad idea. First, this is a bad idea because the standard

Read whole ASCII file into C++ std::string [duplicate]

二次信任 提交于 2019-11-25 22:18:08
问题 This question already has an answer here: How do I read an entire file into a std::string in C++? 12 answers I need to read a whole file into memory and place it in a C++ std::string . If I were to read it into a char[] , the answer would be very simple: std::ifstream t; int length; t.open(\"file.txt\"); // open input file t.seekg(0, std::ios::end); // go to the end length = t.tellg(); // report location (this is the length) t.seekg(0, std::ios::beg); // go back to the beginning buffer = new