standard-library

stdin allows to read with the EOF flag set

萝らか妹 提交于 2020-01-15 08:53:12
问题 On my platform, the following code allows me to successfully read from stdin even if its end-of-file flag is set, which also remains set after the read. To reproduce the behavior, first type the end-of-file shortcut ( Ctrl + D on Unix, Ctrl + Z on Windows) and then type a normal character. #include <stdio.h> // first type the shortcut for EOF, then a single character int main(void) { getchar(); printf("feof(stdin): %s\n", feof(stdin) ? "true" : "false"); int ch = getchar(); if (ch == EOF)

Is there a std::noncopyable (or equivalent)?

风流意气都作罢 提交于 2020-01-13 07:37:07
问题 There's a boost::noncopyable and I have my own noncopyable class in my library. Is there a std::noncopyable or equivalent knocking around in the latest C++ standard? It's a small thing but deriving from such a class makes the intention much clearer. 回答1: No, because there is a standard way to make a class non-copyable: class MyClass { MyClass(const MyClass&) = delete; MyClass& operator=(const MyClass&) = delete; }: A class that is non-copyable can however be made movable by overloading a

How to access a standard-library module in Python when there is a local module with the same name?

江枫思渺然 提交于 2020-01-08 13:26:05
问题 How can a standard-library module (say math) be accessed when a file prog.py is placed in the same directory as a local module with the same name (math.py)? I'm asking this question because I would like to create a package uncertainties that one can use as import uncertainties from uncertainties.math import * Thus, there is a local math module inside the uncertainties directory. The problem is that I want to access the standard library math module from uncertainties/__init__.py. I prefer not

How to access a standard-library module in Python when there is a local module with the same name?

泄露秘密 提交于 2020-01-08 13:23:02
问题 How can a standard-library module (say math) be accessed when a file prog.py is placed in the same directory as a local module with the same name (math.py)? I'm asking this question because I would like to create a package uncertainties that one can use as import uncertainties from uncertainties.math import * Thus, there is a local math module inside the uncertainties directory. The problem is that I want to access the standard library math module from uncertainties/__init__.py. I prefer not

Partially sorting array so last n elements are sorted?

可紊 提交于 2020-01-03 08:40:23
问题 Is there a way to perform a partial sort on an array of data so that the last n elements are sorted? By good I mean using the standard library, not implementing my own sort function (this is what I'm doing right now). Example output (using less comparator): 2 1 4 || 5 6 8 10 Elements after || are all greater than elements than elements before || , but only elements to the right of || (indices closer to the end of the array) are guaranteed to be sorted. This is basically a reversal of the std:

What's the equivalent of cout for output to strings?

微笑、不失礼 提交于 2020-01-02 03:46:14
问题 I should know this already but... printf is to sprintf as cout is to ____ ? Please give an example. 回答1: It sounds like you are looking for std::ostringstream. Of course C++ streams don't use format-specifiers like C's printf() -type functions; they use manipulators. Example, as requested: #include <sstream> #include <iomanip> #include <cassert> std::string stringify(double x, size_t precision) { std::ostringstream o; o << std::fixed << std::setprecision(precision) << x; return o.str(); } int

Requirements on standard library allocator pointer types

99封情书 提交于 2020-01-01 09:02:34
问题 I am trying to write a quadtree sparse matrix class. In short, a quadtree_matrix<T> is either the zero matrix or a quadruple (ne, nw, se, sw) of quadtree_matrix<T> . I'd like eventually to test different allocation schemes since this will probably impact the performance of linear algebra operations. So I will also template quadtree_matrix on a standard allocator type, so that I can reuse existing allocators. I will have to allocate two different kind of data: either a T , or a node , which

Where can I see the list of functions that interact with errno?

天大地大妈咪最大 提交于 2020-01-01 05:07:32
问题 In the book "The C Programming Language" it says: "Many of the functions in the library set status indicators when error or end of file occur. These indicators may be set and tested explicitly. In addition, the integer expression errno (declared in <errno.h> ) may contain an error number that gives further information about the most recent error." Where can I see a list of these functions? 回答1: The standard says this about errno : The value of errno is zero at program startup, but is never

How to embed Python3 with the standard library

孤街浪徒 提交于 2020-01-01 04:25:20
问题 I am attempting to embed Python in an (ultimately multiplatform) C++ app. It's important that my app contains its own Python implementation (in the same way that blender does), so that it is entirely self-contained. (Else it becomes a configuration minefield). I have two options: Attempt to embed Python3 without the standard library (which I have asked here) Attempt to embed Python3 with the standard library. What is required for (2)? With this information I would be able to balance the

Python logging module having a formatter causes AttributeError

家住魔仙堡 提交于 2019-12-30 09:00:40
问题 I am writing a terminal application, which, after passing in -v option, gets, unsurprisingly, verbose. I want to have the output available in the terminal, for easy testing (it gets redirected to a log file when running as cron anyways). However, python logging module doesn't allow me to write out the messages with corresponding levels when using a formatter. (Formatter is copied directly from Python Logging Cookbok) This behavior is not limited to Python3 only. Python2.7 raises the same