大约有 44,000 项符合查询结果(耗时:0.0296秒) [XML]
Get a substring of a char* [duplicate]
...
char subbuff[5];
memcpy( subbuff, &buff[10], 4 );
subbuff[4] = '\0';
Job done :)
share
|
improve this answer
...
How do I create a random alpha-numeric string in C++?
I'd like to create a random string, consisting of alpha-numeric characters. I want to be able to be specify the length of the string.
...
Avoid trailing zeroes in printf()
...") the number to a string buffer then manipulate the string to only have N characters past the decimal point.
Assuming your number is in the variable num, the following function will remove all but the first N decimals, then strip off the trailing zeros (and decimal point if they were all zeros).
...
Replacing instances of a character in a string
...ce(';', ':') + line[10:]
That'll replace all semi-colons in the first 10 characters of the string.
share
|
improve this answer
|
follow
|
...
Is the sizeof(some pointer) always equal to four?
For example:
sizeof(char*) returns 4. As does int* , long long* , everything that I've tried. Are there any exceptions to this?
...
How do I return multiple values from a function in C?
... just silly. In that case, I would return the int and pass the string as a char * and a size_t for the length unless it's absolutely vital for the function to allocate it's own string and/or return NULL.
– Chris Lutz
Apr 12 '10 at 6:14
...
How to print (using cout) a number in binary form?
...senting the value, then stream that to cout.
#include <bitset>
...
char a = -58;
std::bitset<8> x(a);
std::cout << x << '\n';
short c = -315;
std::bitset<16> y(c);
std::cout << y << '\n';
...
Structure padding and packing
...s the following "gaps" into your first structure:
struct mystruct_A {
char a;
char gap_0[3]; /* inserted by compiler: for alignment of b */
int b;
char c;
char gap_1[3]; /* -"-: for alignment of the whole struct in an array */
} x;
Packing, on the other hand prevents compiler ...
C++ lambda with captures as a function pointer
...ector>
#include <functional>
using namespace std;
int ftw(const char *fpath, std::function<int (const char *path)> callback) {
return callback(fpath);
}
int main()
{
vector<string> entries;
std::function<int (const char *fpath)> callback = [&](const char *fpa...
How to find memory leak in a C++ code/project?
..., you should use a delete so that you free the same memory you allocated:
char* str = new char [30]; // Allocate 30 bytes to house a string.
delete [] str; // Clear those 30 bytes and make str point nowhere.
2
Reallocate memory only if you've deleted. In the code below, str acquires a new addre...