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
1
vote
3 answers

Strings taken from user in C are being scrambled

I have written the following C code to get in a list of strings from the user. But the stored strings are giving out weird values. #include #include #define MAX_STRING_LENGTH 50 void readInStrings(char* arr[],int n) { int…
Arjun J Rao
  • 925
  • 1
  • 10
  • 25
1
vote
2 answers

How to serialize a CString using boost

I'm trying to use boost::serialization to replace one part of an existing project that implements its own methods for serialization but are not that good. However, I'm facing some problems because the application uses MFC. I tried to serialize the…
adn
  • 897
  • 3
  • 22
  • 49
1
vote
8 answers

Strange memory management issues in C++ (from a beginner, at least)

I'm new to C++, I have lots of Objective-C experience. I'm trying to have an array of c-strings (that is char **) as an instance variable in my class, which gets allocated and filled in my constructor, and then in another member function I want to…
jbrennan
  • 11,943
  • 14
  • 73
  • 115
1
vote
2 answers

CString error, 'CString': is not a member of 'ATL::CStringT'

I am trying to do this: #include CHAR Filename; // [sp+26Ch] [bp-110h]@1 char v31; // [sp+36Ch] [bp-10h]@1 int v32; // [sp+378h] [bp-4h]@1 GetModuleFileNameA(0, &Filename, 0x100u); CString::CString(&v31, &Filename); But I am getting…
flavour404
  • 6,184
  • 30
  • 105
  • 136
1
vote
1 answer

Convert OLECHAR* to CString in VC++?

How to convert OLECHAR* to CString in VC++ ?
Swapnil Gupta
  • 8,751
  • 15
  • 57
  • 75
1
vote
3 answers

C++, OpenGL: Weird problem with c-strings

I have a C++ problem here which I simply cannot understand. I have 2 slightly different functions. Both of them should do the very same thing. But only one works properly. Method 1: input of the method is 'const string samplerName = "test"' void…
Walter
  • 396
  • 1
  • 5
  • 16
1
vote
6 answers

Manipulating C-style strings?

Hey all, My question is, how do I append two C-style strings into one? Being babied by the C++ way of doing things (std::string), I've never touched C-style strings and need to learn more about them for my current development project. For example: …
epicasian
  • 45
  • 1
  • 1
  • 5
1
vote
2 answers

Using CString to Convert int and Send to Console

My console application attempts to write an integer to the console: int i = 170; CString cs; cs.Format( L"%d", i ); wcout << cs << endl; I expect "170" to be written to the console, but what happens is "00E21280". This is the address. I have…
Jim Fell
  • 13,750
  • 36
  • 127
  • 202
1
vote
2 answers

C++ - Pushing a C-String onto a Template Stack

I am sure that for most this is a very easy question. But I am writing a token recoginzer for XML in c++ and I am using a stack to make sure there are matching begining and end tags. Well my tags are c strings... char BeginTag[MAX]; I am trying to…
Johnrad
  • 2,637
  • 18
  • 58
  • 98
1
vote
2 answers

How to Convert CString LPStr

I want to read a value from registry using the following method: char* cDriveStatus=ReadFromRegistry(HKEY_CURRENT_USER,_T(NDSPATH),m_szDriveName); I tried converting using GetBuffer,m_szDriveName.GetBuffer(0) but this again shows error: error…
Simsons
  • 12,295
  • 42
  • 153
  • 269
1
vote
5 answers

C++ Storing copy of string in vector of pairs

I have a private attribute in a class that is defined as vector > data;. I add data to this vector with data.push_back(make_pair(p, r));. Later when I go to get the data out of the vector I get bad data for the p value. The data…
Ian Burris
  • 6,325
  • 21
  • 59
  • 80
1
vote
3 answers

cstring trouble for a beginner

I'm trying to make a program that read a file line by line and then put the readed line into a a linked list, my problem is to add the string to list. Look at the code, in the else test you can see my…
user265767
  • 559
  • 3
  • 12
  • 27
1
vote
6 answers

Arrays of strings in C

I need to hold an array of C strings. Now I know C strings are just an array of chars so essentially what I want is a 2d array of chars. The strings I'm trying to store will also never exceed 6 characters. My plan is to initialize a char array with…
Ian Burris
  • 6,325
  • 21
  • 59
  • 80
1
vote
2 answers

Is it safe to return local CStringW to the caller?

I have a function defined a local variable typed in CStringW, is it safe to return this object to the caller by value, not by reference?
Thomson
  • 20,586
  • 28
  • 90
  • 134
1
vote
1 answer

Passing CString to IIS ServerSupportFunction function in ISAPI extension

I've been given an ISAPI extension dll compiled in VC6 which calls "ServerSupportFunction" through MFC's CHttpServerContext class. The code looks something like (assume Ctx is object of the class CHttpServerContext) CString str; str =…
Ohad
  • 166
  • 1
  • 6