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
0
votes
1 answer

Failed to assign an Ansi char array to MFC CStringW

I have an Ansi char array like and want to initialize a CStringW (WCHAR specialization of CString template). But the CString object does not have copy the chars from the array. CStringW sSample = "ABC"; int length = sSample.GetLength(); // returns…
harper
  • 13,345
  • 8
  • 56
  • 105
0
votes
2 answers

A list of known string issues in VC++ 6.0

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…
Bharani
  • 303
  • 1
  • 8
  • 16
0
votes
1 answer

cstring m_pszdata doesn't match converted char* in UNICODE

I tested the Unicode conversion with a UNICODE MFC dialog app, where I can input some Chinese in the edit box. After reading in the characters using DDX_Text(pDX, IDC_EDIT1, m_strUnicode) UpdateDate(TRUE) the m_pszdata of m_strUnicode shows "e0…
LSSG
  • 3
  • 1
0
votes
6 answers

Memory allocated in char * var; declaration

In C, declaring a char pointer like this char* p="Hello"; allocates some memory for a string literal Hello\0. When I do this afterwards p="FTW"; what happens to the memory allocated to Hello\0? Is the address p points to changed?
nischayn22
  • 447
  • 3
  • 14
0
votes
1 answer

Combining std::strings and C-Strings causes buffer overrun

I am attempting to make a function that will make combining C Strings and std::strings a little easier in my C++ WinAPI Application. So instead of doing this: TCHAR res[MAX_PATH]; _stprintf(res, _T("In functionX(): error occured where the variable…
sazr
  • 24,984
  • 66
  • 194
  • 362
0
votes
1 answer

Memory Leak when Allocating a New Char Array (c string)

I am writing a program that uses character arrays / c strings. Whenever I run the program, valgrind throws a 'definitely lost' block warning: ==8011== [X] bytes in [Y] blocks are definitely lost in loss record 1 of [Z] ==8011== at 0x4A065BA:…
Tanaki
  • 2,575
  • 6
  • 30
  • 41
0
votes
3 answers

How to convert CString to UCHAR array?

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
Naruto
  • 9,476
  • 37
  • 118
  • 201
-1
votes
6 answers

copy from char* to char[]

is there any way to copy from char* to char[] other than using strcpy? I tried this and does not work.. for ex char* t1 = "hello"; char t2[6]; t2 = t1; It is not compiling.. saying that incompatible types of assignment of 'char*' to char[6] Thank…
in His Steps
  • 3,075
  • 6
  • 30
  • 38
-1
votes
3 answers

Converter and compresser between ASCII and Binary

I am trying to make a very easy converter/compressor; the program should take a file with 4 different types of ASCII characters and writ it out as binary to a file. The program should also read the binary file and convert it to ASCII and print it…
user265767
  • 559
  • 3
  • 12
  • 27
-1
votes
2 answers

Cstrings in C++

why this code gives the wrong output?? Output is 5 and 9, shouldn't it be 5 and 4. Here is the code int main { char a[10] ={'a','b','c','d','e'}; char c[] = {'q','t','y','t'}; cout<
-1
votes
1 answer

A bunch of questions about C++'s cstring

I have a few questions I would like to clarify about cstrings: 1) Initialization: When declaring an array of characters as follows, does C++ automatically defines it as a cstring? or (as I believe) an array of characters? char a[10]; In other words,…
Gil Dekel
  • 355
  • 4
  • 15
-1
votes
1 answer

Why can I still access the char pointer returned by std::string::c_str() out of the scope of string?

string pointer pp is temporary, why is it still correct to cout the c_str after I delete the pointer? #include #include using namespace std; int main(){ const char* tt = NULL; { string * pp = new string("big"); …
Ridox
  • 1,073
  • 13
  • 18
-1
votes
2 answers

Query on Memory free

I am facing compilation error in the below code. I am writing a function to free memory in C++ template inline void kill(T& v) { free(v); v=0; } I am calling this function for freeing Class object and sometime to free a string and…
-1
votes
1 answer

How to convert CString to const char *

I have problems converting CString to const char *. I tried the methods from other forums and msdn way and it doesn't work: CString value1("text1"); const char * value2= LPCTSTR(value1); Any idea ?
Clax
  • 207
  • 2
  • 9
-1
votes
2 answers

Implementing C strcpy but getting segfault

I'm trying to implement strcpy within my main but I'm not sure why I'm segfaulting on the first while loop. Could someone shed light? int main() { const char* src = "this is a test"; char* dest = "abcdefgqwerty"; char* head = dest; …
Mozbi
  • 1,399
  • 1
  • 17
  • 25