std

warning: fopen() call [duplicate]

可紊 提交于 2020-01-06 23:20:44
问题 This question already has answers here : Why am i getting this warning in “if (fd=fopen(fileName,”r“) == NULL)”? (6 answers) Closed last year . hi I'm programming with stdlib under linux. The gcc emits the following warning for the following line of code, any idea why is that? FILE *fd; if ( fd = fopen( filename, "rw" )== NULL ) { and the warning is: warning: assignment makes pointer from integer without a cast. How this can be happen , according to the stdlib documentation the return type of

warning: fopen() call [duplicate]

▼魔方 西西 提交于 2020-01-06 23:18:48
问题 This question already has answers here : Why am i getting this warning in “if (fd=fopen(fileName,”r“) == NULL)”? (6 answers) Closed last year . hi I'm programming with stdlib under linux. The gcc emits the following warning for the following line of code, any idea why is that? FILE *fd; if ( fd = fopen( filename, "rw" )== NULL ) { and the warning is: warning: assignment makes pointer from integer without a cast. How this can be happen , according to the stdlib documentation the return type of

Storing vector of pointers in a file and reading them again

眉间皱痕 提交于 2020-01-06 10:20:13
问题 Assume the following code: // Base class class Base { public: Base(int val) : hi(val) { } virtual void PublicMethod() { /* Do something */} private: int hi; }; // Child class class Child : public Base { public: Child(int val) : Base(val) { } void PublicMethod() { /* Do something */} }; // Vector of pointers to prevent slicing std::vector<std::shared_ptr<Base>> list; (...) // Fill list with mixed data of class Base and Child After the list is filled with objects, I want to store the data into

Multi-armed bandits with Rcpp

泪湿孤枕 提交于 2020-01-06 07:07:38
问题 I am translating the epsilon-greedy algorithm for multiarmed bandits from here. This is a rather nice demonstration of the power and elegance of Rcpp. However, the results from this version do not tally with the one that is mentioned in the link above. I am aware that this is probably a very niche question but have no other venue to post this on! A summary of the code is as follows. Basically, we have a set of arms, each of which pays out a reward with a pre-defined probability and our job is

Multi-armed bandits with Rcpp

馋奶兔 提交于 2020-01-06 07:06:46
问题 I am translating the epsilon-greedy algorithm for multiarmed bandits from here. This is a rather nice demonstration of the power and elegance of Rcpp. However, the results from this version do not tally with the one that is mentioned in the link above. I am aware that this is probably a very niche question but have no other venue to post this on! A summary of the code is as follows. Basically, we have a set of arms, each of which pays out a reward with a pre-defined probability and our job is

Removing Windows library dependencies

浪子不回头ぞ 提交于 2020-01-06 06:46:49
问题 I have a couple of classes here that I would like to remove window library dependencies for portability reasons. One for blocking processes and the other for blocking threads. Both of these classes compile & runs fine as is... As for the BlockProcess class it is currently using a HANDLE for a mutex and using function calls such as: { CreateMutex() , CloseHandle() & GetLastError() }. As for the BlockThread class it uses a pointer to a CRITICAL_SECTION calling functions such as: {

How do I use std::regex_replace to replace string into lowercase?

风格不统一 提交于 2020-01-06 01:17:18
问题 I find this regex for replacement Regex replace uppercase with lowercase letters Find: (\w) Replace With: \L$1 My code string s = "ABC"; cout << std::regex_replace(s, std::regex("(\\w)"), "\\L$1") << endl; runs in Visual Studio 2017. output: \LA\LB\LC How do I write the lowercase function mark in C++? 回答1: Since there is no the magic like \L , we have to take a compromise - use regex_search and manually covert the uppers to lowers. template<typename ChrT> void RegexReplaceToLower(std::basic

Cleanup at unexpected function end, std equivalent

我与影子孤独终老i 提交于 2020-01-05 08:23:06
问题 I have some function where I need to use a member variable(a vector of custom classes). At the end of this function this member needs to be cleared but it needs to stay as a member for the duration of this function. Another problem is that the function can end prematurely due to custom error handling of the program. Yet the member still needs to be cleared. I first moved this member at the beginning in a local variable using std::move. This worked pretty well but it now turns out I need the

C++ MAC OS X cannot write to ~/Library/Application Support/<appname>

吃可爱长大的小学妹 提交于 2020-01-05 08:16:18
问题 If i save files inside the .app bundle, it saves OK, but apple recommends saving files inside the Application Support under ~/Library/Application Support/appname or ~/Library/Application Support/bundleid I tried both, but I am always getting an exception. I am getting a path to the Application Support, which is /Users/myname/Library/Application Support/com.company.appname/ or /Users/myname/Library/Application Support/AppName/ com.company.appname is specified correctly inside my info.plist ,

const char * to std::basic_iostream

吃可爱长大的小学妹 提交于 2020-01-05 07:20:40
问题 I have a pointer to a const *char buffer as well as it's length, and am trying to use an API (in this case, the AWS S3 C++ upload request) that accepts an object of type: std::basic_iostream <char, std::char_traits <char>> Is there a simple standard C++11 way to convert my buffer into a compatible stream, preferably without actually copying over the memory? 回答1: Thanks to Igor's comment, this seems to work: func(const * char buffer, std::size_t buffersize) { auto sstream = std::make_shared