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

Why does this simple c++ c style string reverse method throw an access violation exception?

I have been working through Stroustrup's C++ programming language, and I am having difficulties with an early exersize. The task is to build a method rev that reverses a c style string. I think my logic is right, but I get an error when I try to…
Ben313
  • 1,662
  • 3
  • 20
  • 32
0
votes
4 answers

Why I do not get a segmentation fault?

Possible Duplicate: Why don’t I get a segmentation fault when I write beyond the end of an array? I was just playing with pointers when I realized that something strange was happening. I am aware that whenever we want to copy a string src to…
Leaurus
  • 376
  • 3
  • 13
0
votes
3 answers

C string comparison problem in c++

I've been having trouble with comparison in my c++ program. This is the boiled down version. #include "stdafx.h" #include #include using namespace std; int main(int argc, char *argv[]) { …
ThatGuyYouKnow
  • 450
  • 5
  • 10
0
votes
1 answer

Syntax errors when trying to use CString in Visual C++

My project is not happy regarding include cstring. It generates errors like: Error 10 error C2061: syntax error : identifier 'using' C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\cstring 18 1 fgdll Error 95 error…
vico
  • 17,051
  • 45
  • 159
  • 315
0
votes
1 answer

Compare function for std::sort sort C-strings

Here is I what I am doing, basically sort an array of dynamically generated C-Strings, it's going to be a combination of "abc", and the length is less than 5 for the sake of brevity. What is confusing/interesting is how to configure the compare…
Cong Hui
  • 633
  • 1
  • 13
  • 25
0
votes
1 answer

sprintf segfault while printf is fine

Is there any simple thing that I might have overlooked for when printf("%s/%s\n", str1, str2); prints out the string while sprintf(str3, "%s/%s", str1, str2); causes the program to crash? This only happens on Ubuntu (latest release), which I am…
calccrypto
  • 8,583
  • 21
  • 68
  • 99
0
votes
3 answers

C string replacing backslashes

I currently using C string headers and C++ and have hit a problem. I have a long path: C:\bla\bla\bla\bla I need to change the backslashes to double backslashes so that my OS_CopyFile() function can read it properly but I don't know how? I get my…
Natalie Carr
  • 3,707
  • 3
  • 34
  • 68
0
votes
2 answers

stl map const_iterator and g++ error

I'm trying to port some windows"s MFC class to linux because I have to port a windows software to linux. here is the code I need to port 165: SMapCI it = _s$.find("nchairs"); 166: if (it==_s$.end()) return 10; 167: int n =…
ramone
  • 266
  • 1
  • 2
  • 10
0
votes
4 answers

Extract a floating point number from a CString

I want to extract a floating point number from a CString formatted as: (example extract 22.760348) Incidence_angle(inc)[deg] :22.760348 Basically I am reading a plain text file containing some parameters, and I want to perform some…
shaunakde
  • 3,009
  • 3
  • 24
  • 39
0
votes
1 answer

Is it ok to return a stack object for a CString and why /GR causes undefined behavior to dynamic_cast?

I have polymorphic classes and I want to convert an object via dynamic_cast(A) although with compiler optimization /GR I receive a message that it may cause undefined behavior. I'm using static_cast instead, but it does no run-time checks and is…
Vinícius
  • 15,498
  • 3
  • 29
  • 53
0
votes
3 answers

Getting rid of newline in CString in C++

I have a html/xml document that is originally a CString and I want to get rid of all the newlines, essentially put everything into one line. I've tried converting it to std::String and using: #include #include…
minusatwelfth
  • 191
  • 6
  • 14
0
votes
2 answers

objective-C string encoding problem

Ok, I'm fairly new to C sockets but I just need to do some simple sendto() and recvfrom() calls to get a string out across a network, using multicast sockets. After looking around and reading several guides (including Beej's), I found the code below…
Josh Bradley
  • 4,630
  • 13
  • 54
  • 79
0
votes
3 answers

Getting the ending position of CString

How can I find the position of the end of a CString? I am trying the int end = str.Find(L'\n'); but it returns -1. I want in particular to get a substring from a CString from some position in the CString till the end of it. The problem is I cannot…
arjacsoh
  • 8,932
  • 28
  • 106
  • 166
0
votes
2 answers

VC++ 6.0 application crashing inside CString::Format when %d is given

A VC++ 6.0 application is crashing when doing a CString::Format operation with %d format specifier. This does not occur always but occurs when the application memory grows upto 100MB or more. ALso sometimes same crash observed when a CString copy is…
viswanathan
0
votes
1 answer

How to insert a new character in a StringStream and extract to string within a loop in C++?

I am not sure what the issue is with my code. I would like for the character to be updated and inserted into the stringstream on each iteration of the for-loop and extracted to a string that I can later use to append to a char[] variable. The output…
user1457479
  • 3
  • 1
  • 2