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

Converting an int into a base 2 cstring/string

In visual studio on my PC I can use itoa() to convert from a base ten int to a base 2 c-string. However when I am on a Linux machine that function isn't supported. Is there another quick way of doing this kind of conversion? I know how to use a…
Schuyler
  • 509
  • 1
  • 9
  • 19
4
votes
5 answers

Multiple string concatenation

I'm new to the C language and Loadrunner. How do I do a string concatenation in C. Pseudo code: String second = "sec"; String fouth = "four"; System.out.println("First string" + second +"Third" + fouth);
user2537446
  • 43
  • 1
  • 1
  • 3
4
votes
2 answers

Error: Conversion to non-scalar type

I am making a set of derived classes for an assignment. I am instructed to use char arrays (c-strings). When I compile I keep getting the error: Homework11.cpp: In function âint main()â: Homework11.cpp:72: error: conversion from âchar [10]â to…
art3m1sm00n
  • 389
  • 6
  • 9
  • 19
4
votes
2 answers

Link error CString

I'm getting a linker error using CString the error is: error LNK2001: unresolved external symbol "private: static class ATL::CStringT > > CConfiguration::_campaignFolderPath"…
akif
  • 12,034
  • 24
  • 73
  • 85
4
votes
3 answers

C++ difference between automatic type conversion to std::string and char*

As a learning exercise, I have been looking at how automatic type conversion works in C++. I know that automatic type conversion should generally be avoided, but I'd like to increase my knowledge of C++ by understanding how it works anyway. I have…
Paul Stephenson
  • 67,682
  • 9
  • 49
  • 51
4
votes
1 answer

char* scope inside C++ containers

With the following: #include std::set global = std::set(); void x() { const char *c = "a"; const char *d = "b"; global.insert(c); global.insert(d); } int main() { x(); for (std::set
Matoe
  • 2,742
  • 6
  • 33
  • 52
4
votes
3 answers

How to convert an std::string to C-style string

I am programming in C++. As basic as this question is I cannot seem to find an answer for it anywhere. So here is the problem: I want to create a C-style string however I want to put an integer variable i into the string. So naturally, I used a…
user1413793
  • 9,057
  • 7
  • 30
  • 42
4
votes
1 answer

How to manage string slices with less overhead?

I'm dealing with giant (up to 2GB) strings and their slices in C++ program. C-style strings seem to be unreliable under such circumstances, but can be sliced trivially (without '\0' at the end). On the other hand, as I understood,…
leventov
  • 14,760
  • 11
  • 69
  • 98
3
votes
1 answer

How to convert part of a char array into an NSString*?

char arr[] = "abcdefg"; // I know I can do this NSString *s = [[NSString alloc] initWithCString:arr encoding:NSUTF8StringEncoding]; If I want to convert part of the arr array into an NSString*? say cde rather then the whole string abcdefg? How do I…
neevek
  • 11,760
  • 8
  • 55
  • 73
3
votes
2 answers

Pointers and cstring length

I am setting pointers here one to point to name and one to point to name again but get the lenth. How come when i use cout << strlen(tail); it keeps telling me the lenth is 3? Even if i enter something that is 12? #include #include…
soniccool
  • 5,790
  • 22
  • 60
  • 98
3
votes
3 answers

in c++, if I pass a CString to a function by reference and assign it to another CString it is truncated

some simple code has begun failing in an sdk I've been working with, also it apparently has been working correctly for a long time, and indeed I'm almost positive I have compiled parts of the code like this and they have worked, but recently have…
3
votes
1 answer

How to view the value of a unicode CString in VC6?

I'm using Visual Studio 6 to debug a C++ application. The application is compiled for unicode string support. The CString type is used for manipulating strings. When I am using the debugger, the watch window will display the first character of…
JadeMason
  • 1,181
  • 1
  • 14
  • 23
3
votes
1 answer

Expose Haskell-functions through foreign export ccall fails for CStrings

I made a short Haskell-program that exposes functions for C or Python. Followed http://www.haskell.org/ghc/docs/7.0.3/html/users_guide/ffi-ghc.html#ffi-library to the letter and that worked okay for exporting Ints. Want to export Strings and made…
3
votes
6 answers

Reversing a string, weird output c++

Okay, so I'm trying to reverse a C style string in C++ , and I'm coming upon some weird output. Perhaps someone can shed some light? Here is my code: int main(){ char str[] = "string"; int strSize = sizeof(str)/sizeof(char); char…
volk
  • 1,196
  • 1
  • 12
  • 31
3
votes
3 answers

when you push_back heap-allocated char into a vector in c++

I'm having trouble inserting char* into a vector< char*> When I do the following: string str = "Hello b World d" char *cstr, *p; vector redn; cstr = new char [ (str.size)+1 ]; strcpy(cstr, str.c_str()); //here I tokenize "Hello b World d" p…
Mang
  • 33
  • 3