stdstring

std::string - get data from start to end

Hi guys, I want to get some data between some 2 indexes. For example, I have string: "just testing..." and I need string from 2 till 6. I should get: 'st tes'. What function can do this for me? ...

Why isn't string assignment optimised when the length is known to the compiler?

I was playing around today with some timing code and discovered that when asigning a string literal to std::string, that it was around 10% faster (with a short 12 char string, so likly even bigger difference for large strings) to do so with a literal of known length (using the sizeof operator) than not. (Only tested with the VC9 compiler...

C++ bitwise operators for std::string

Hi, my question is about how to use bitwise operators on C++ std::string... through overloading or as function does not matter Example for an working XOR/^ function for std::string: std::string XOR(std::string value, std::string key) { std::string retval(value); long unsigned int klen = key.length(); long unsigned int vlen = val...

How to get a basic preg_match_all replacement for std::string in C++?

with "basic" is meant: Only the operators "+" (->following..) and "|" (->or) are needed. Prototype: preg_match_all(std::string pattern, std::string subject, std::vector<std::string> &matches) Usage Example: std::vector<std::string> matches; std::string pattern, subject; subject = "Some text with a lots of foo foo and " + char(255) ...

C++ Program Always Crashes While doing a std::string assign

I have been trying to debug a crash in my application that crashes (i.e. asserts a * glibc detected free(): invalid pointer: 0x000000000070f0c0 **) while I'm trying to do a simple assign to a string. Note that I'm compiling on a linux system with gcc 4.2.4 with an optimization level set to -O2. With -O0 the application no longer cras...

Invalid free while performing a std::string assign with -O2 set in g++

Before I get blasted on opening another question, this question is related to another question that I opened a few days ago: http://stackoverflow.com/questions/2303740/c-program-always-crashes-while-doing-a-stdstring-assign After investigating further based on some of the answers I came up with more questions and more information that ...

using std::string with Qt causes run-time error on destruction

Hi. I have a Qt app that uses another library where the function output is std::string instead of a QString. So in my program I have a method void doSomething() { ... std::string std_string = MyExternalLibraryThatReturnsSTLstring.getString(); QString myQString = QString::fromStdString(std_string); ... process(myQString); ... } When ...

Using a std::string iterator to find the start and end of it's string

Hi, Given just a std::string iterator, is it possible to determine the start and end points of the string? Supposing that I don't have access to the string object and so cannot call string.begin() and string.end(), and all I can do is increment or decrement the iterator and test the value. Thanks, Phil ...

Avoiding improper std::string initialization with NULL const char* using g++

A there any g++ options which can detect improper initialization of std::string with NULL const char*? I was in the process of turning some int fields into std::string ones, i.e: struct Foo { int id; Foo() : id(0) {} }; ...turned into: struct Foo { std::string id; Foo() : id(0) {} //oooops! }; I completely overlooked...

Managed c++ std::string not accessible in unmanaged c++

In unmanaged c++ dll i have a function which takes constant std::string as argument Prototype : void read ( const std::string &imageSpec_ ) I call this function from managed c++ dll by passing a std::string. When i debug the unmanaged c++ code the parameter imageSpec_ shows the value correctly but does not allow me to copy that value...

C++ addition overload ambiguity

I am coming up against a vexing conundrum in my code base. I can't quite tell why my code generates this error, but (for example) std::string does not. class String { public: String(const char*str); friend String operator+ ( const String& lval, const char *rval ); friend String operator+ ( const char *lval, const String& rv...

Char* vs std::string

Possible Duplicate: C++ char* vs std::string Is there any advantage to using char*'s instead of std::string? I know char*'s are usually defined on the stack, so we know exactly how much memory we'll use, is this actually a good argument for their use? Or is std::string better in every way? ...

Way to get unsigned char into a std::string without reinterpret_cast?

I have an unsigned char array that I need in a std::string, but my current way uses reinterpret_cast which I would like to avoid. Is there a cleaner way to do this? unsigned char my_txt[] = { 0x52, 0x5f, 0x73, 0x68, 0x7e, 0x29, 0x33, 0x74, 0x74, 0x73, 0x72, 0x55 } unsigned int my_txt_len = 12; std::string my_std_string(reinterpret_c...

Can a std::string contain embedded nulls?

For regular C strings, a NULL signifies the end of data. What about std::string, can I have a string with embedded NULLS? ...

unformatted input to a std::string instead of c-string from binary file.

ok i have this program working using c-strings. I am wondering if it is possible to read in blocks of unformatted text to a std::string? I toyed arround with if >> but this reads in line by line. I've been breaking my code and banging my head against the wall trying to use std::string, so I thought it was time to enlist the experts. ...

How to replace all occurrences of a character in string?

What is the effective way to replace all occurrences of a character with another character in std::string? ...

How to store an XML file content into a std::string or CString, at compilation time ?

Hello The XML contains symbols that the C++ may misinterpret (like the // in http://www.w3.org/2000/10/XMLSchema) I am wondering if you know about clean ways to include some hard-coded XML into a std::string or a CString, at compile time. (in deed I'm trying to encode an .xsd file for validating some xml input, because I don't want to...

segfault when trying to access a string member of a class

I have a class Message that has a std::string as a data member, defined like this: class Message { // Member Variables private: std::string text; (...) // Member Functions public: Message(const std::string& t) : text(t) {} std::string getText() const {return text;} (...) }; Thi...

C++ looking for String.Replace()

Hello i have a a char array in C++ which looke like {'a','b','c',0,0,0,0} now im wrting it to a stream and i want it to appear like "abc " with four spaces insted of the null's i'm mostly using std::stiring and i also have boost. how can i do it in C++ basicly i think im looking for something like char hellishCString[7] = {'a','b'...

std::string vs string literal for functions

I was wondering, I normally use std::string for my code, but when you are passing a string in a parameter for a simply comparison, is it better to just use a literal? Consider this function: bool Message::hasTag(string tag) { for(Uint tagIndex = 0; tagIndex < m_tags.size();tagIndex++) { if(m_tags[tagIndex] == tag) ...