standard-library

Why does gets(stdin) return an integer? And other errors [duplicate]

廉价感情. 提交于 2019-12-18 08:57:24
问题 This question already has answers here : What is going on with 'gets(stdin)' on the site coderbyte? (3 answers) Closed 4 months ago . I am new to C programming (although I have experience with Java). After reading some tutorials, I decided to start solving coding challenges on Coderbyte. The first challenge I tried was this one: Challenge Have the function FirstFactorial(num) take the num parameter being passed and return the factorial of it. For example: if num = 4, then your program should

where is stdin defined in c standard library?

℡╲_俬逩灬. 提交于 2019-12-18 04:45:17
问题 I found this line in stdio.h : extern struct _IO_FILE *stdin; Based on this 'extern' keyword, i assume this is just a declaration. I wonder where is stdin defined and initialized? 回答1: It's defined in the source code of your C library. You typically only need the headers for compilation, but you can find the source code for many open-source standard libraries (like glibc). In glibc, it's defined in libio/stdio.c as like this: _IO_FILE *stdin = (FILE *) &_IO_2_1_stdin_; Which is in turn

Compile-time reflection in C++1z? [closed]

旧城冷巷雨未停 提交于 2019-12-17 23:15:33
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 5 years ago . There is a study group in the C++ standardization committee to provide compile-time reflection in C++1z or after. I would like to know what is exactly the purpose and how powerful the expected tools will be? For example will it be possible to name functions or classes using these tools? struct A {int f() {return

Is there a standard java exception class that means “The object was not found”?

 ̄綄美尐妖づ 提交于 2019-12-17 22:55:07
问题 Consider a function of the following general form: Foo findFoo(Collection<Foo> foos, otherarguments) throws ObjectNotFoundException { for(Foo foo : foos){ if(/* foo meets some condition*/){ return foo; } } throw new ObjectNotFoundException(); } A concrete case, for example, would be: User findUserByName(Collection<User> users, String name) throws ObjectNotFoundException { for(User user : users){ if(user.getName().equals(name)){ return user; } } throw new ObjectNotFoundException(); } These

Design of std::ifstream class

不羁岁月 提交于 2019-12-17 20:49:02
问题 Those of us who have seen the beauty of STL try to use it as much as possible, and also encourage others to use it wherever we see them using raw pointers and arrays . Scott Meyers have written a whole book on STL, with title Effective STL. Yet what happened to the developers of ifstream that they preferred char* over std::string . I wonder why the first parameter of ifstream::open() is of type const char* , instead of const std::string & . Please have a look at it's signature: void open

Is there a way to check if an istream was opened in binary mode?

人走茶凉 提交于 2019-12-17 16:32:29
问题 I'm using an istream which could be stringstream, ifstream or a user-defined stream type and I need to know if, in the case of an ifstream, it was not opened in binary mode (so I can throw an exception). I have tried the following method: if ((_is.flags() & ios::binary) == 0) throw exception(...) but no exception is ever thrown. The test fails in this case because _is.flags() returns 0x201 and ios::binary is 0x20. Is there a way to find out if a stream was opened in text mode? 回答1: flags()

Why does str.split not take keyword arguments?

纵然是瞬间 提交于 2019-12-17 16:18:58
问题 I came across this - in my view - strange behaviour: "a b c".split(maxsplit=1) TypeError: split() takes no keyword arguments Why does str.split() not take keyword arguments, even though it would make sense? I found this behavior both in Python2 and Python3. 回答1: See this bug and its superseder. str.split() is a native function in CPython, and as such exhibits the behavior described here: CPython implementation detail: An implementation may provide built-in functions whose positional

What is std::decay and when it should be used?

给你一囗甜甜゛ 提交于 2019-12-17 08:00:28
问题 What are the reasons for the existence of std::decay? In what situations is std::decay useful? 回答1: <joke>It's obviously used to decay radioactive std::atomic types into non-radioactive ones.</joke> N2609 is the paper that proposed std::decay . The paper explains: Simply put, decay<T>::type is the identity type-transformation except if T is an array type or a reference to a function type. In those cases the decay<T>::type yields a pointer or a pointer to a function, respectively. The

Are int8_t and uint8_t intended to be char types?

纵然是瞬间 提交于 2019-12-17 07:23:22
问题 Given this C++11 program, should I expect to see a number or a letter? Or not make expectations? #include <cstdint> #include <iostream> int main() { int8_t i = 65; std::cout << i; } Does the standard specify whether this type can or will be a character type? 回答1: From § 18.4.1 [cstdint.syn] of the C++0x FDIS (N3290), int8_t is an optional typedef that is specified as follows: namespace std { typedef signed integer type int8_t; // optional //... } // namespace std § 3.9.1 [basic.fundamental]

stdio.h not standard in C++?

杀马特。学长 韩版系。学妹 提交于 2019-12-17 06:46:33
问题 I know most compilers allow both: #include <stdio.h> //and #include <cstdio> But someone argued that <stdio.h> is not actually C++ standard. is that true? 回答1: stdio.h is standard, but deprecated. Always prefer cstdio in C++. [n3290: C.3.1/1]: For compatibility with the Standard C library, the C++ standard library provides the 18 C headers (D.5), but their use is deprecated in C++. [n3290: D.5/3]: [ Example: The header <cstdlib> assuredly provides its declarations and definitions within the