Questions tagged [cstring]

Refers to 0-terminated strings as popularized by C, as well as the header-files `string.h` and `cstring`.

A C string is a sequence of non-zero bytes terminated by a NUL byte (0x00), usually used to store ASCII or UTF-8 text.

C strings are defined as char arrays in C and C++, where char is an 8-bit type. C strings can be referred to using a char pointer.

Extensions to the basic C string (e.g. to 16-bit wchar_t "wide strings") also exist in various programming environments.

In C++, the standard std::string class interoperates with C strings via the .c_str() method, though beware that std::strings can contain embedded 0-bytes.

488 questions
5
votes
1 answer

MFC C++ How do I display a const char value in MessageBox?

I hope that the title was good enough to help explain what is needed. After solving this much of my project should be done. When I did this char e[1000] = "HELLO"; CString msg; msg.Format(_T("%s"), e); MessageBox(msg); the…
Ashton
  • 83
  • 1
  • 3
  • 12
5
votes
2 answers

Shall we treat BSTR type in COM as value or reference?

From book ATL Internals, I knew BSTR is different from OLECHAR*, and there are CComBSTR and CString for BSTR. According MSDN Allocating and Releasing Memory for a BSTR, I knew memory management responsibility for caller/callee. Take this line from…
Raymond
  • 885
  • 10
  • 28
5
votes
2 answers

Unexpected behaviour of memset()

I am initializing array with 99 in all the elememts #include #include int main(){ int a[10]; memset(a,99,10); std::cout<
dead programmer
  • 4,223
  • 9
  • 46
  • 77
4
votes
2 answers

URL escaping MFC strings

How do you URL escape an MFC CString?
Raul Agrait
  • 5,938
  • 6
  • 49
  • 72
4
votes
4 answers

Which is better code for converting BSTR parameters to ANSI in C/C++?

So far I've discovered I can convert incoming BSTRs to ANSI in two (of many?) ways, and I'm curious to know whether one is "better" than the other with respect to speed / efficiency etc. The way I've been using for a while is use the USES_CONVERSION…
bugmagnet
  • 7,631
  • 8
  • 69
  • 131
4
votes
3 answers

C++/CLI Printing contents of CString to console

C++ newbie here with a quick question. How do I print the contents of CString to the Console? Doing this int main(array ^args) { CString cs1 = _T("Hy"); CString cs2 = _T(" u"); CString cs3 = cs1 + cs2; …
Klaus Nji
  • 18,107
  • 29
  • 105
  • 185
4
votes
3 answers

Conversion of UTF-8 char * to CString

How do I convert a string in UTF-8 char* to CString?
Greenhorn
  • 658
  • 2
  • 8
  • 24
4
votes
5 answers

NULL terminated string and its length

I have a legacy code that receives some proprietary, parses it and creates a bunch of static char arrays (embedded in class representing the message), to represent NULL strings. Afterwards pointers to the string are passed all around and finally…
dimba
  • 26,717
  • 34
  • 141
  • 196
4
votes
2 answers

C++ Delete array of c-strings/other type of array

[EDIT] Okay, so that makes sense, thank you sharptooth and CashCow. You can't delete data allocated as const, which makes string literals out of the question. So if I change my initialization to look like this: char **groups = new char*[2]; char…
michael.bartnett
  • 787
  • 7
  • 20
4
votes
2 answers

Is std::string a better idea than char* when you're going to have to pass it as a char*?

In a recent question, I learned that there are situations where you just gotta pass a char* instead of a std::string. I really like string, and for situations where I just need to pass an immutable string, it works fine to use .c_str(). The way I…
Maulrus
  • 1,787
  • 2
  • 17
  • 27
4
votes
7 answers

char* as an argument to a function in C

When passing a char* as an argument to a function, should the called function do a free on that string? Otherwise the data would be "lost" right and the program would leak data. Or are char* handled in a special way by the compiler to avoid everyone…
inquam
  • 12,664
  • 15
  • 61
  • 101
4
votes
1 answer

Trying to pass a CStringArray gives error cannot access private member declared in class 'CObject'

I'm getting a strange error telling me that I cannot access private member declared in class 'CObject' when simply trying to pass a CStringArray to a function I have written to break it up into pieces. I've commented out my entire function code so I…
JayB
  • 397
  • 6
  • 21
4
votes
4 answers

getting the length of an array using strlen in g++ compiler

could someone explain why i am getting this error when i am compiling the source using following g++ compiler #include #include using namespace std; int main() { char source_language[50]; …
KItis
  • 5,476
  • 19
  • 64
  • 112
4
votes
1 answer

CString += operator performance issues

I am working on an older MFC/C++ project that parses large text files using MFC's CString class to handle strings. I noticed that during the parsing process there's a lot of adding of small parts to an overall large CString object as…
c00000fd
  • 20,994
  • 29
  • 177
  • 400
4
votes
2 answers

C++: how to convert ASCII or ANSI to UTF8 and stores in std::string

My company use some code like this: std::string(CT2CA(some_CString)).c_str() which I believe it converts a Unicode string (whose type is CString)into ANSI encoding, and this string is for a email's subject. However, header of the email (which…
Joe
  • 841
  • 2
  • 10
  • 25