stdstring

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 function, needed "const char* cstring_array[]"? ...

string contains valid characters

I am writing a method whose signature is bool isValidString(std::string value) Inside this method I want to search all the characters in value are belongs to a set of characters which is a constant string const std::string ValidCharacters("abcd") To perform this search I take one character from value and search in ValidCharacter...

What is the Linux equivalent of: MultiByteToWideChar & WideCharToMultiByte?

I am working with a class that wraps the std::wstring, this code needs to be cross platform, are there equivalents to the windows functions: MultiByteToWideChar & WideCharToMultiByte on linux? Thank you. ...

converting an integer to a std::string accepted by an std::pair

I have this function that converts an integer to a std::string: std::string intToStr(const int n) { stringstream ss; ss << n; return ss.str(); } It's worked well so far, but now I'm trying to construct a string to put into a std::pair, and I'm having some trouble. Given an integer variable hp and a function that returns a...

Reference-counting of std::string

I'm looking at the code for basic_string (that is bundled with g++ 4.2.1). The copy constructor makes use of a grab() function to "grab" a copy of a string (increment its reference-count): _CharT* _M_grab( const _Alloc& __alloc1, const _Alloc& __alloc2 ) { return (!_M_is_leaked() && __alloc1 == __alloc2) ? _M_refcopy() : _M_clone(__a...

returning a std::string with an vector

hi, I'm trying to get "CMtoaPlugin::listArnoldNodes()" to return an "array" of strings std::vector<std::string> ArnoldNodes = CMtoaPlugin::listArnoldNodes(); std::vector<std::string>::iterator it; for ( it=ArnoldNodes.begin() ; it < ArnoldNodes.end(); it++ ) { printf("initialize shader %s\n", *it); } but this is ...

How to convert std::string to NSString?

Hi I am trying to convert a standard std::string into a NSString but i'm not having much luck I can convert successfully from an NSString to a std::string with the following code NSString *realm = "Hollywood"; std::string REALM = [realm cStringUsingEncoding:[NSString defaultCStringEncoding]]; However i get a compile time error when i...

conversion from 'std::string' to non-scalar type requested

I have trouble implementing my class. It should be able to initialize from std::string. So I wrote a copy (?) constructor: CVariable (std::string&, const int p_flags = 0); I'm trying to make an object of CVariable: MCXJS::CVariable s_var = (string)"good job"; I'm getting the following error: F:\Projekty\MCXJS\src\main.cpp|8|error:...

WinAPI File In-/Output with std::strings instead of char arrays?

Hi, due to performance reasons I didn't feel like using fstream for just one time. Seems like a very bad idea to use WinAPI functions with a std::string instead of a plain char array. All in all I would like you to tell me why the following snippet just won't work (empty stBuffer stays empty) and what I'd need to do to get it fixed. Th...

C++ remove character from string

Hi! I am currently trying to implement deleting characters from a text field in C++. If the user hits Backspace, the following code is executed. There is currently no cursor, it should just remove the last character... if (mText.length() > 0){ mText.erase( mText.length() - 1, 1); // mText.resize(mText.length() - 1); } This wo...

Easily initialise an std::list of std::strings?

In C++0x, what I want would be: std::list<std::string> colours = {"red", "blue", "green", "grey", "pink", "violet"}; What's the easiest way in standard, non-0x C++? ...

"Invalid conversion" error with conditional operator

I'm getting compile error in this line: cout << (MenuItems[i].Checkbox ? (MenuItems[i].Value ? txt::mn_yes : txt::mn_no) : MenuItems[i].Value) Error: menu.cpp|68|error: invalid conversion from 'int' to 'const char*' menu.cpp|68|error: initializing argument 1 of 'std::basic_string<_CharT, _Traits, _Alloc>::basic_string(const _CharT*...

Struct containing std::string being passed to lua

I have working C++ code using swig which creates a struct, passes it to lua (essentially by reference), and allows manipulation of the struct such that the changes made in the lua code remain once I've returned to the C++ function. This all works fine until I add a std::string to the struct, as shown here: struct stuff { int x; ...

How to Pass a std::string variable into a function

Hi I have a C++ Method that takes one variable the method signature is like this. DLL returnObject** getObject( const std::string folder = "" ); I tried passing in const std::string myString = "something"; but i get the following error No matching function call to ... getObject( std::string&); I have a couple questions here. 1. ...

convert std::string to LPCSTR with trailing or leading '\0'

Hi, How can I convert std::string to LPCSTR while preserving '\0' characters? I want to use the result on OPENFILENAME.lpstrFilter which requires the filter to contain '\0' as delimiters. std::string.c_str() seems to strip and trim '\0' Thanks in advance! ========================== (How do I properly add a comment to the responses...

No "add esp,4" for virtual functions returning std::string

I've been looking at DynObj and decided to do my own experimentation with vftables. I'm working with Visual Studio 2010 and created a console main that instantiates an object with a virtual function that returns an std::string. The test code in main attempts to call the object's public virtual function using a pointer obtained from the...

Why is my MD5 value printing with extra "f" characters?

I have strange problem when using at() method of std::string. I'd like to calculate md5 hash for given string using this library: http://sourceforge.net/projects/libmd5-rfc/files/ Hash is calculated correctly, but there is a problem with printing it human way. The output is: af04084897ebbf299b04082d105ab724 ffffffaf040848ffffff97ffffffe...

Is possible to get automatic cast from user-defined type to std::string using cout?

As in the question, if I define a string operator in my class: class Literal { operator string const () { return toStr (); }; string toStr () const; }; and then I use it: Literal l1 ("fa-2bd2bc3e0"); cout << (string)l1 << " Declared" << endl; with an explicit cast everything goes right, but if I remove the (string) the c...