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

What is the difference between CString in vc6 and vc7?

What is the difference between CString in vc6 and vc7?
yesraaj
  • 46,370
  • 69
  • 194
  • 251
1
vote
1 answer

convert a string into cstring

I am trying to convert my string to a cstring in an mfc Application. I have searched this forum for hours without any result. my code is: void CSokevinduView::OnBnClickedsoker() { string O1,O2,O3,info; ifstream…
1
vote
1 answer

a swift questions about String and c strcpy

I want to call a c++ function in swift bool getId3Info(const char * filename , char *artist , char * title ) { // get the file's id3v2 tag, write info back strcpy(artist,(const char*) id3v2tag->artist().toCString(true)); …
liaogang
  • 508
  • 3
  • 16
1
vote
2 answers

‘memcopy’ was not declared in this scope

#include #include #include using namespace std; void printArray(int* arr, int size) { cout << "Printing the array..." << endl; for (int index = 0; index < size; index++) { cout << arr[index] <<…
sakthisundar
  • 3,278
  • 3
  • 16
  • 29
1
vote
1 answer

Escape "%" symbol when calling CString::FormatV

I'm using var args in a file i/o function. It works fine unless the string which is wanting to be outputted contains a % and there are no additional arguments. E.g. the string would cause the issue, as an example. The code is…
Luke
  • 560
  • 6
  • 26
1
vote
1 answer

Why i can't compare CString in MFC

This line. UpdateData(true); if( m_OldPassword.Compare(d.pass) && m_NewPassword.Compare(m_ConfirmPassword) ) m_OldPassword, m_NewPassword, m_ConfirmPassword is variable i added from EditControl m_OldPassword.Compare(d.pass) Result =true…
KayTran
  • 11
  • 4
1
vote
2 answers

How to use random_shuffle with CString?

I would like to shuffle the characters present in CString varible. How do i do it? Std provide a finction called random_shuffle() which can be used to shuffle std::string in the following way std::string s("ThisIsSample"); …
1
vote
2 answers

C++ string() comparison with a c-string. WHY DOES THIS WORK?

So this code is for a command input to be entered in any random order and it will return the value that comes after your input. Amt_Range is a digit checking function. Why does this work. It should be able to due to the pointer comparison.?? More…
DisplayName
  • 196
  • 3
  • 12
1
vote
4 answers

Returning a C string from a function in C

I have written a function in c to convert a base-10 number into its binary representation with 16 bits. A space should also appear in the output of this function, E.G.: 00000000 00000001 = 1. The conversion itself works correctly, but I'm having…
1
vote
1 answer

Encode/decode C-string literals

I have a text file containing something that behaves like C-strings. For example: something = "some text\nin two lines\tand tab"; somethingElse = "some text with \"quotes\""; Fetching things between quotes is not a problem. Problem is that later…
Marek R
  • 32,568
  • 6
  • 55
  • 140
1
vote
6 answers

c++ char* converted from a string using strdup doesn't equal original raw string

What I'm wondering is why converting a string to a char* seems to make the new char* not equal to the literal string it came from. If I have: //raw versions of the string: string s = "fun"; char* c = "fun"; char* s_convert = strdup(s.c_str());…
xgord
  • 4,606
  • 6
  • 30
  • 51
1
vote
0 answers

Converting char arrays with literal escape sequences into char

I have a C tokenizer library I'm using for a personal project. It returns escaped characters as a char array of literals. So for example the string "\n" gets returned as this char array: [][n] Instead of this (desired) array: [\n] Is there an easy…
drewying
  • 51
  • 5
1
vote
2 answers

How to pass a cstring from Delphi

I'm writing a tcp client in Delphi for a server that has a series of messages defined as c structs. Below is an example conversion of one of the messages: struct { int32 Reserved; cstring Name; int32 flags; } msg1 = record …
Jason Southwell
  • 351
  • 2
  • 9
1
vote
2 answers

Using argv[1] as a filename problems

I'm trying to read the file named by argv[1], but I have no idea on how I go about doing this. It feels like it's something simple, the error message I'm getting when compiling is, main.cpp: In function ‘void* ReadFile(char**,…
Impulse
  • 155
  • 11
1
vote
3 answers

How to separate strings based on tokens

#include using namespace std; void main() { string target_str = "1.2.3.4:3333 servertype=simics,arch=x86"; string host_str; string port_str; string type_str; string arch_str; host_str =…
Santhosh Kumar
  • 381
  • 1
  • 5
  • 13