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
2
votes
2 answers

Traversing nested vectors of strings

There's an issue in my code with nested vectors of strings. It is not printing the strings. void foo(vector > const & vcp){ vector >::const_iterator i(vcp.begin()); vector
badmaash
  • 4,775
  • 7
  • 46
  • 61
2
votes
2 answers

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

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…
Abruzzo Forte e Gentile
  • 14,423
  • 28
  • 99
  • 173
2
votes
2 answers

What techniques are available to test if a character string is all spaces?

char *p = " woohoo"; int condition = /* some calculation applied to p */ /* to look for all 0x20/blanks/spaces only */ if (condition) { } else { printf("not "); } printf("all spaces\n");
EvilTeach
  • 28,120
  • 21
  • 85
  • 141
2
votes
6 answers

What is the most efficient way to convert STL string array to const char* array?

We have: std::string string_array[2]; string_array[0] = "some data"; string_array[1] = "some more data"; char* cstring_array[2]; What is the most efficient way to copy data from string_array to cstring_array? Or pass string_array to the…
hoxnox
  • 355
  • 1
  • 4
  • 16
2
votes
2 answers

How to concatenate multiple CString

All functions return CString, this is a MFC code and must compile in 32 & 64 bits. Currently I'm using CString sURI = GetURL(); sURI += GetMethod(); sURI += "?"; sURI += GetParameters(); Exists any manner to do the same like: CString sURI =…
Gustavo V
  • 152
  • 1
  • 1
  • 4
2
votes
1 answer

Const char conversion error

I am getting the following error with gcc. invalid conversion from ‘char**’ to ‘const char**’ With this code. void foo( const int &argc, const char **argv ); int main( int argc, char *argv[] ) { foo( argc, argv ); …
Thomas
  • 2,939
  • 6
  • 32
  • 29
2
votes
2 answers

How (if needed) to free dynamic memory when marshaling CString from C++ to C#?

I have CString cs on C++ side and IntPtr ip on C# side which contains value of cs through marshaling mechanism. Then, I simply get needed String as Marshal.PtrToStringAnsi(ip) and everything works fine, but I am wondering should I and if should,…
Draško
  • 2,119
  • 4
  • 41
  • 73
2
votes
2 answers

is there a way to use cin.getline() without having to define a char array size before hand?

Basically my task is having to sort a bunch of strings of variable length ignoring case. I understand there is a function strcasecmp() that compares cstrings, but doesn't work on strings. Right now I'm using getline() for strings so I can just read…
zebraman
  • 2,424
  • 5
  • 20
  • 21
2
votes
1 answer

strcmpi code wont compile but strcmp will?

I have a question on why my code wont compile when i use strcmpi. I tested this same code with strcmp and that worked. Not sure why this does not work. here is the compile error i get : gcc -std=c99 strcmpi_test.c -o strcmpi_test strcmpi_test.c: In…
Max Powers
  • 1,119
  • 4
  • 23
  • 54
2
votes
2 answers

Cannot convert CString to BYTE array

I need to convert CString to BYTE array. I don't know why, but everything that I found in internet does not work :( For example, I have CString str = _T("string"); I've been trying so 1) BYTE *pbBuffer = (BYTE*)(LPCTSTR)str; 2) BYTE *pbBuffer =…
2
votes
2 answers

Most efficient way to search array of string objects in c++?

I've been searching for some more information on this topic, and can't seem to find the answer I'm looking for, so I hope you can help! Part of an assignment I'm working on is to write a program that searches an array of strings (address book), and…
bran.io
  • 72
  • 1
  • 9
2
votes
2 answers

C++ Add byte value to CString as int

Let's start off by stating that I have 0 xp with C++. I have a byte array which is filled with data. Example: byte 0: 1 byte 1: 75 byte 2: 125 byte 3: 66 byte 4: 114 byte 5: 97 byte 6: 109 I have a CString in C++ which is supposed to get all the…
bram
  • 181
  • 1
  • 7
2
votes
1 answer

CString replacing multiple Whitespace MFC

I have CStrings with single/multiple whitespaces in my MFC application. I have to replace them with single underscore. Example: sampleString= "A B C D E" --> "A_B_C_D_E" But when I use sampleString.Replace(" ",'_'), underscore appears for each…
Codename_DJ
  • 553
  • 1
  • 11
  • 40
2
votes
2 answers

NSString stringWithCString:encoding: - not copying the Cstring?

I need to compute a signature (a kind of a hash) for my object. The computation requires many per-character operations, so to speed this procedure up, my code operates on CString, and after that converts computed CString to final NSString. The stub…
Voyteck
  • 354
  • 2
  • 13
2
votes
3 answers

Searching CStrings in C++

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…
Konrad
  • 39,751
  • 32
  • 78
  • 114