大约有 118 项符合查询结果(耗时:0.0135秒) [XML]
C libcurl get output into a string
...nc(void *ptr, size_t size, size_t nmemb, std::string *s)
{
s->append(static_cast<char *>(ptr), size*nmemb);
return size*nmemb;
}
int main(void)
{
CURL *curl = curl_easy_init();
if (curl)
{
std::string s;
curl_easy_setopt(curl, CURLOPT_URL, "curl.haxx.se");
curl_easy...
C++ template constructor
...t;typename T> C(T*);
};
template <typename T> T* UseType()
{
static_cast<T*>(nullptr);
}
Then to create an object of type C using int as the template parameter to the constructor:
C obj(UseType<int>());
Since you can't pass template parameters to a constructor, this so...
Clean code to printf size_t in C++ (or: Nearest equivalent of C99's %z in C++)
...MAX:
printf("If the answer is %" PRIuMAX " then what is the question?\n", static_cast<uintmax_t>(a));
share
|
improve this answer
|
follow
|
...
Using scanf() in C++ programs is faster than using cin?
...
also use cin.tie(static_cast<ostream*>(0)); for better performance
– Mohamed El-Nakib
Feb 5 '14 at 7:58
add a c...
Is there a simple way to convert C++ enum to string?
...sh_back(temp.str()); \
os << enumName << "::" << strings[static_cast<int>(value)]; \
return os;}
To use this in your code, simply do:
AWESOME_MAKE_ENUM(Animal,
DOG,
CAT,
HORSE
);
shar...
Difference between 'new operator' and 'operator new'?
...e your own container, you can call operator new directly, like:
char *x = static_cast<char *>(operator new(100));
It's also possible to overload operator new either globally, or for a specific class. IIRC, the signature is:
void *operator new(size_t);
Of course, if you overload an opera...
What exactly is nullptr?
..._t to any pointer type. Rely on the implicit conversion if possible or use static_cast.
The Standard requires that sizeof(nullptr_t) be sizeof(void*).
share
|
improve this answer
|
...
Can't use modulus on doubles?
...U>
constexpr double dmod (T x, U mod)
{
return !mod ? x : x - mod * static_cast<long long>(x / mod);
}
//Usage:
double z = dmod<double, unsigned int>(14.3, 4);
double z = dmod<long, float>(14, 4.6);
//This also works:
double z = dmod(14.7, 0.3);
double z = dmod(14.7, 0);
do...
What is a C++ delegate?
...tFunc( void* this__, int a, int b, int c)
{
SomeClass* this_ = static_cast< SomeClass*>( this__);
this_->SomeFunc( a );
this_->someMember = b + c;
}
};
void ScheduleEvent( void (*delegateFunc)( void*, int, int, int), void* delegateContext);
...
...
How can I pass a member function where a free function is expected?
...t;< "\n";
}
};
void forwarder(void* context, int i0, int i1) {
static_cast<foo*>(context)->member(i0, i1);
}
int main() {
somefunction(&non_member, 0);
foo object;
somefunction(&forwarder, &object);
}
...