cstring

MFC: std::string vs CString?

你离开我真会死。 提交于 2019-12-12 08:18:25
问题 Using C++ with MFC. Coming from a C# background I typically just use string for all, well, strings. I use them for class members, method parameters, and method return values. Now in C++ I've got std::string, CString, char *, LPCTSTR, and more. As I design my data members, method parameters, and method return values which type(s) should I be using? Ease of use is important and CString seems to offer that but my instinct is toward portable standards although portability is pretty low on my list

A list of known string issues in VC++ 6.0

女生的网名这么多〃 提交于 2019-12-12 04:22:35
问题 I am looking for some list containing all string related issues in VC++ 6.0 which are fixed in later service packs such as this one. Can anyone please help me on this regard? The reason for my search is this: We face some string related issues in our VC++ 6.0 based product. I am looking for other potential issues. Thanks. 回答1: You can seach MSDN knowledge base, troubleshooting and support. For example, a search with CString keyword will reveal many bug fixes. 回答2: I realise it can be a pain

Working with WinAPI functions which use C style strings as OUT parameters

橙三吉。 提交于 2019-12-12 03:56:20
问题 Given a WinAPI function which returns it's result via a C style string OUT parameter e.g.: int WINAPI GetWindowTextW( _In_ HWND hWnd, _Out_ LPTSTR lpString, _In_ int nMaxCount ); Is there a better way of using the function than what I'm doing below? HWND handle; // Assume this is initialised to contain a real window handle std::wstring title; wchar_t buffer[512]; GetWindowTextW(handle, buffer, sizeof(buffer)); title = buffer; The above code works, but I have the following issues with it: The

How to convert CString to UCHAR array?

女生的网名这么多〃 提交于 2019-12-12 03:16:00
问题 I have a cstring object str = "5043", now i want to convert to Hex and put it in UCHAR array like UCHAR sample[2]; Sample[0] = 0X50 Sample[1] = 0X43 How can i do this? please advice me 回答1: You can scan the hex values directly from the string using sscanf() , something like below: UCHAR sample[2]; for ( int i = 0; i < str.length() / 2 ; i++) { sscanf( (str.substr(i*2,2)).c_str(), "%hx", &sample[i]); } h is for short and x is for hexadecimal obviously. Also, this assumes that the UCHAR array

Replace characters in C string

半世苍凉 提交于 2019-12-12 02:47:06
问题 Given this C string: unsigned char *temp = (unsigned char *)[@"Hey, I am some usual CString" UTF8String] How can I replace "usual" with "other" to get: "Hey, I am some other CString". I cannot use NSString functions ( replaceCharactersInRange / replaceOccurencesOfString , etc.) for performance reasons. I have to keep it all at low level, since the strings I'll be dealing with happen to exceed 5MB, and therefore the replacements (there will be a lot of replacements to do) take about 10 minutes

Extract CString between tags

家住魔仙堡 提交于 2019-12-12 01:45:17
问题 How can I extract a CString between two tags ? <tag1>My Text</tag1> I don't want to calculate the start and end position then use Mid, maybe there is another easier method using STL ? 回答1: Disclaimer: the following idea is bad and should not be used in production code. I'm assuming you just want a quick hack for testing. Use a regular expression to match the tags. Microsoft provides this in CAtlRegExp. If you're using Visual Studio 2008 or newer, download ATL here. Then, just provide myString

C String Pointer Function strdel

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-11 10:46:57
问题 Can someone please explain me why I get "Segmentation fault..." and how to fix it on this bit of code? #include<stdio.h> int str_length(char *s) { int length = 0, i; for(i = 0; *s; i++) { s++; } return i; } char *strdel(char *s, int pos, int n) { int i; char *p, str[] = ""; p = str; for(i = 0; i < str_length(s) - n + 1; i++) { if(i >= pos) { *(p + i) = *(s + i + n); } else { *(p + i) = *(s + i); } } s = str; return s; } int main() { char *str = "abcdef"; printf("str_lengh: %d\n", str_length

Should I cast a CString passed to Format/printf (and varargs in general)?

心不动则不痛 提交于 2019-12-11 06:36:36
问题 I recently took in a small MCF C++ application, which is obviously in a working state. To get started I'm running PC-Lint over the code, and lint is complaining that CStringT's are being passed to Format. Opinion on the internet seems to be divided. Some say that CSting is designed to handle this use case without error, but others (and an MSDN article) say that it should always be cast when passed to a variable argument function. Can Stackoverflow come to any consensus on the issue? 回答1:

using boost string algorithm with MFC CString to check for the end of a string

这一生的挚爱 提交于 2019-12-11 03:59:22
问题 I need to check whether my CString object in MFC ends with a specific string. I know that boost::algorithm has many functions meant for string manipulation and that in the header boost/algorithm/string/predicate.hpp could it be used for that purpose. I usually use this library with std::string . Do you know a convenient way to use this library also with CString ? I know that the library is generic that can be used also with other string libraries used as template arguments, but it is not

How to write INT64 to CString

眉间皱痕 提交于 2019-12-10 15:33:51
问题 I am coding in c++ windows. INT64 dirID = -1; CString querySQLStr = _T(""); querySQLStr.Format(L"select * from ImageInfo where FolderPath=%64d;", dirID); querySQLStr always like this: select * from ImageInfo where FolderPath= 1214; is it right to use %64d? Many Thanks 回答1: I don't have a windows machine handy to test this on, but I think CString should accept this: querySQLStr.Format("%I64d", dirID); It's probably worth noting that this is windows specific, but since you're using CString I