standard-library

Case Insensitive String comp in C

耗尽温柔 提交于 2019-12-17 06:31:52
问题 I have two postcodes char* that I want to compare, ignoring case. Is there a function to do this? Or do I have to loop through each use the tolower function and then do the comparison? Any idea how this function will react with numbers in the string Thanks 回答1: There is no function that does this in the C standard. Unix systems that comply with POSIX are required to have strcasecmp in the header strings.h ; Microsoft systems have stricmp . To be on the portable side, write your own: int

Does std::mt19937 require warmup?

霸气de小男生 提交于 2019-12-17 05:39:47
问题 I've read that many pseudo-random number generators require many samples in ordered to be "warmed up". Is that the case when using std::random_device to seed std::mt19937, or can we expect that it's ready after construction? The code in question: #include <random> std::random_device rd; std::mt19937 gen(rd()); 回答1: Mersenne Twister is a shift-register based pRNG (pseudo-random number generator) and is therefore subject to bad seeds with long runs of 0s or 1s that lead to relatively

Reading a text file backwards in C

那年仲夏 提交于 2019-12-17 04:34:23
问题 What's the best way to read a file backwards in C? I know at first you may be thinking that this is no use whatsoever, but most logs etc. append the most recent data at the end of the file. I want to read in text from the file backwards, buffering it into lines - that is abc def ghi should read ghi , def , abc in lines. So far I have tried: #include <stdio.h> #include <stdlib.h> void read_file(FILE *fileptr) { char currentchar = '\0'; int size = 0; while( currentchar != '\n' ) { currentchar =

Why is it OK to return a 'vector' from a function?

强颜欢笑 提交于 2019-12-17 04:12:52
问题 Please consider this code. I have seen this type of code several times. words is a local vector. How is it possible to return it from a function? Can we guarantee it will not die? std::vector<std::string> read_file(const std::string& path) { std::ifstream file("E:\\names.txt"); if (!file.is_open()) { std::cerr << "Unable to open file" << "\n"; std::exit(-1); } std::vector<string> words;//this vector will be returned std::string token; while (std::getline(file, token, ',')) { words.push_back

Any reason why an std::ofstream object won't close properly?

自古美人都是妖i 提交于 2019-12-13 16:34:54
问题 I noticed in my C++ code that anytime I close an std::ofstream object I'm unable to reopen the file I closed with std::ifstream . std::ifstream 's open function will always fail. Is there anything 'extra' I can do to ensure that my std::ofstream object closes properly? Someone's probably going to ask to see my specific code so for the sake of keeping this post small I've pastied it here. In my code after running through case a or d all std::ifstream open calls fail. (Prior to posting this

Is Java Cryptography standard libraries in Android run as native code

有些话、适合烂在心里 提交于 2019-12-13 10:26:16
问题 I am integrating standard java cryptography classes in my Android application, but I noticed that the AES algorithm is not that fast, it cannot encrypt more than about 5 Kb per second, so do someone know if I can get more performance if I implement my own cryptography methods using NDK? or it is just being done already in the standard library? any suggestions is appreciated 回答1: Is Java Cryptography standard libraries in Android run as native code On older devices, javax.crypto is implemented

Directly Reference Python's Standard Library

北战南征 提交于 2019-12-12 17:37:16
问题 So it turns out that PyQt redefines a function hex() , which unfortunately renders the python standard library hex() unusable. I'm working on a large software project and it's been set up with *imports: from PyQt4.QtCore import * from PyQt4.QtGui import * ...etc I need the standard python hex() function, is there any way for me to reference it? I'm thinking of a stdlib.hex() or something like that? Currently my ugly workaround is: pyHex = hex from PyQt4.QtCore import * from PyQt4.QtGui import

codeblocks autocomplete / calltips not working for C standard library functions

久未见 提交于 2019-12-12 03:34:44
问题 I'm trying to start using code::blocks to do some C programming in just to learn. I was hoping to use the codecompletion / calltips feature (e.g. when typing say "printf" it popsup a handy dropdown box that shows the parameters. I've made a new project and a new file in that project called "hello.c" #include <stdio.h> int main(){ int test=0; printf("%d",test); return 0; } but midway through typing prin---only "priority_queue and private" show up, no printf functions, and nothing happens when

Reverse concat in Elixir

◇◆丶佛笑我妖孽 提交于 2019-12-11 12:56:49
问题 Is there a standard library function in Elixir (or Erlang) to concatenate the reverse of a list in front of some other list? Basically I'm looking for an equivalent of reverse_::: in Scala. The rationale is that it's handy when implementing a tail-recursive algorithm on a list. During recursion, you hold on to some of the elements for later by adding them onto the front of an accumulator list. In the end you can reverse-concat them onto the remainder of the assembled list in one go (which

Why std::size() is not a member of std in gcc 8.2.0

穿精又带淫゛_ 提交于 2019-12-11 10:42:46
问题 I'm trying to teach myself some C++17. Why is the compiler throwing an error for the below code snippet? #include <iostream> #include <vector> #include <iterator> int main() { std::vector<int> v = { 3, 1, 4 }; std::cout << std::size(v) << '\n'; int a[] = { -5, 10, 15 }; std::cout << std::size(a) << '\n'; } The compiler throws the following error manish@Manish-Tummala:~/c_files$ g++ 6.cpp -o - 6.out 6.cpp: In function ‘int main()’: 6.cpp:8:23: error: ‘size’ is not a member of ‘std’ std::cout <