cstring

CString maximum length

What is the maximum length in characters a CString object can hold? ...

Searching CStrings in C++

Hi all, I was wondering if there is a native C++ (or STL/Boost) function which will search a CString for a specified string? e.g. CString strIn = "Test number 1"; CString strQuery = "num"; bool fRet = SomeFn(strIn, StrQuery); if( fRet == true ) { // Ok strQuery was found in strIn ... I have found a small number of functions lik...

How would you improve this algorithm? (c string reversal)

Working through some programming interview challenges I found online, I had to write an algorithm to reverse a const char * and return a pointer to a new char *. I think I have it, but to make it work properly I had to do some wonky stuff - basically having to account for the null-terminating character myself. Somehow I feel this is wron...

How to Convert CString and ::std::string ::std::wstring to each other?

CString is quit handy, while std::string is more compatible with stl container. I am using hash_map, however, hash_map does not support CString as key, so I wish I could convert CString into std::string, is it possible? Write a CString hash function seems take lots of time. CString ------> std::string ? how can I do? std::string -----...

string array with garbage character at end

I have a char array buffer that I am using to store characters that the user will input one by one. My code below works but has a few glitches that I can't figure out: when I execute a printf to see what's in Buffer, it does fill up but I get garbage characters at the end it won't stop at 8 characters despite being declared as char Bu...

What is the difference between CString in vc6 and vc7?

What is the difference between CString in vc6 and vc7? ...

Pros and Cons of different string types in C++

Sorry to start another of those unanswerable questions on SO, but I'm just curious as to the pros and cons of all the different string types in C++. My particular question is between MFC's CStrings and std::string (since I'm doing Windows only software), but this would extend to any of the string formats in C++. What do you all thing i...

CSTRING to char *

Hi All, We are using the CString class throughout most of our code. However sometimes we need to convert to a char *. at the moment we have been doing this using variable.GetBuffer(0) and this seems to work ( this mainly happens when passing the Csting into a function where the function requires a char *). The function accepts this and ...

Problems with string

Hi. Im working with a cstring function that is supposed to compare the values of two strings, MyString and m2. I have #include so its definitely not that. these are my errors. (74) : error C2275: 'MyString' : illegal use of this type as an expression (74) : error C2660: 'MyString::length' : function does not take 1 arguments (76) : err...

escape characters in a CString

How can you put escape characters (like newline character -- \n) to a CString? ...

Convert CString to character array?

How to convert CString in MFC to char[] (character array) ...

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

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 (an...

URL escaping MFC strings

How do you URL escape an MFC CString? ...

mfc copy certain sections of a CString

Let's say I have a CString variable carrying the string "Bob Evans". I want to copy from position 4 until the end of the original CString to a new CString, but I am having trouble finding semantics examples for this: CString original("Bob Evans"); // Below is what I'm trying to do // CString newStr = original.copy(4, original.GetLength(...

A list of known string issues in VC++ 6.0

Hi All, 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. ...

VC++ 6.0 application crashing inside CString::Format when %d is given.

A VC++ 6.0 application is crashing when doing a CString::Format operation with %d format specifier. This does not occur always but occurs when the application memory grows upto 100MB or more. ALso sometimes same crash observed when a CString copy is done. The call stack would look like this mfc42u!CFixedAlloc::Alloc+82 mfc42u!CString:...

objective-C string encoding problem...

Ok, I'm fairly new to C sockets but I just need to do some simple sendto() and recvfrom() calls to get a string out across a network, using multicast sockets. After looking around and reading several guides (including Beej's), I found the code below which does the job of listening for messages sent over a multicast socket (which is what ...

Best way to find a whitespace-delimited word in a CString

example: "select * from somewhere where x = 1" I want to find the whitespace-delimited "where", but not the "where" within "somewhere". In the example "where" is delimited by spaces, but it could be carriage returns, tabs etc. Note: I know regex would make it easy to do (the regex equivalent would be "\bwhere\b"), but I don't want to a...

Avoiding memory leaks while mutating c-strings

For educational purposes, I am using cstrings in some test programs. I would like to shorten strings with a placeholder such as "...". That is, "Quite a long string" will become "Quite a lo..." if my maximum length is set to 13. Further, I do not want to destroy the original string - the shortened string therefore has to be a copy. The...

Why does the original CString get overwritten when passing a copy to the DrawText function with the DT_MODIFYSTRING option?

I've already found a workaround to this problem, but was just wondering if anyone knew what was actually happening to cause the problem I was seeing. My guess is that it has something to do with mutability of strings, but I thought the CString object accounted for that in the copy constructor. The following code causes mFileName to be ...