Is it possible to print out only a certain section of a C-string, without making a separate substring?

Is it possible to print out only the last 5 bytes of this string? Yes, just pass a pointer to the fifth-to-the-last character. You can determine this by string + strlen(string) – 5. What about the first 5 bytes only? Use a precision specifier: %.5s #include <stdio.h> #include <string.h> char* string = “Hello, how are … Read more

How do you convert CString and std::string std::wstring to each other?

According to CodeGuru: CString to std::string: CString cs(“Hello”); std::string s((LPCTSTR)cs); BUT: std::string cannot always construct from a LPCTSTR. i.e. the code will fail for UNICODE builds. As std::string can construct only from LPSTR / LPCSTR, a programmer who uses VC++ 7.x or better can utilize conversion classes such as CT2CA as an intermediary. CString cs … Read more

Why do I get a segmentation fault when writing to a “char *s” initialized with a string literal, but not “char s[]”?

See the C FAQ, Question 1.32 Q: What is the difference between these initializations? char a[] = “string literal”; char *p = “string literal”; My program crashes if I try to assign a new value to p[i]. A: A string literal (the formal term for a double-quoted string in C source) can be used in … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)