stdstring

How to convert std::string to NSString?

我的未来我决定 提交于 2019-12-28 08:02:11
问题 Hi I am trying to convert a standard std::string into an 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 try the following NSString *errorMessage = [NSString stringWithCString:REALM encoding:[NSString defaultCStringEncoding]]; The error I get is Cannot convert

C++ LPSTR and string trouble with zero-terminated strings

人盡茶涼 提交于 2019-12-25 18:37:08
问题 I'm using GetOpenFileName function from Winapi , and I'm applying filter to the select file dialog. THIS works perfectly: LPSTR mfilter = "Filter\0*.PDF\0"; ofn.lpstrFilter = mfilter; if(GetOpenFileName(&ofn)){ ... THIS fails (dialog opens but no filters apply): string mfilter = "Filter\0*.PDF\0"; ofn.lpstrFilter = mfilter.c_str(); if(GetOpenFileName(&ofn)){ ... I need to use std:string because I'm getting the file extension via parameters and this type facilitates the concatenation but I'm

std::string Array Element Access

ε祈祈猫儿з 提交于 2019-12-25 08:19:24
问题 Despite being a Project Euler program, the following code doesn't actually concern it much. I want to add 50 100-digit numbers, and I'm assigning each digit of each number to an element in the array addends[100][50]. I'd then add up each digit/place individually, and carry over extra digits. The numbers are being read in from a text file named Input.txt , and it merely contains all the numbers. http://projecteuler.net/problem=13 I'm having trouble assigning characters to elements of a string

std::string values become corrupted in Qt 5 [duplicate]

﹥>﹥吖頭↗ 提交于 2019-12-25 08:14:53
问题 This question already has answers here : const reference data member bound to a temporary initializing that reference in a constructor (2 answers) Closed 3 years ago . I am trying to use the Presage text-prediction platform in a Qt5 project but keep getting errors due to std::strings being corrupted. I have this class providing string contexts for the predictive system: class SomeClass : public ParentClass { public: SomeClass(const std::string& _past_context) : past_context(_past_context) { }

gcc inconsistent about string type [duplicate]

£可爱£侵袭症+ 提交于 2019-12-25 03:52:28
问题 This question already has answers here : Conditional operator used in cout statement (2 answers) Closed 5 years ago . I have the following test program: #include <string> #include <iostream> int main() { std::string s; std::string a = "sd"; std::cout << a==s ? "y" : "n"; return 0; } Trying to compile this with g++ test.cpp gives the following cryptic error: error: no match for 'operator==' (operand types are 'std::basic_ostream<char>' and 'std::string {aka std::basic_string<char>}') std::cout

std::string.c_str() returning a weird characters

主宰稳场 提交于 2019-12-25 02:57:56
问题 In my project, I use to load textures by specifying its file name. Now, I made this function const char* app_dir(std::string fileToAppend); that returns the main s argv[0] and change the application name by the fileToAppend . Since I cannot make the string manipulation easy with a char*, I use the std::string . My texture loader takes a const char* for file name so need to switch back to c_str(), now it generates a sequence of ASCII symbol characters (bug). I already fix the problem by

variable has incomplete type std::String; string.h has many errors

僤鯓⒐⒋嵵緔 提交于 2019-12-24 19:03:12
问题 something is very wrong with strings. I have been using them for weeks without issue, but halfway through Monday, I started having strange issues: [Clang IntelliSense] Error: variable has incomplete type 'std::string' whenever I try to make a string. similar errors occur when I try wstring and ostringstream , but not stringstream . initializing std::string* s also works fine but s->append(...) results in "member has access into incomplete type 'std::string'" this all came about because visual

Multiple problems linking mysqlpp_d.lib

喜夏-厌秋 提交于 2019-12-24 12:46:26
问题 Today I added a class which manages the connection to a MySQL Server. It will be multi-threaded, so I want to use mysql++. I downloaded the newest version and compiled it in debug mode without any errors. Once I added the compiled mysqlpp_d.lib to my solutions, and of course the other requirements too (mysql 5.0 include and lib), I got some linker errors. Error 17 error LNK1169: one or more multiply defined symbols found C:\Users\root\Documents\Visual Studio 2010\Projects\C++\xxxx\binaries

Trouble with cast operators converting to Visual Studio 2013

爷,独闯天下 提交于 2019-12-24 09:37:58
问题 I have been using a simple char buffer class for a number of years under Visual Studio 2005 and 2008. I converted to VS 2013 today and I am getting ambiguous conversion errors in different scenarios. I have removed unneeded portions of the code: #include <string> class ACP { public: ACP(const char* const init) : ourStr_(_strdup(init)), size_(strlen(init) + 1) { } virtual ~ACP() { free(ourStr_); } // // casting operators // operator char* () { return ourStr_; } operator const char* const ()

Does the address of the result of std::string::operator[] point to a writable, nul-terminated buffer?

雨燕双飞 提交于 2019-12-24 02:47:10
问题 I am modifying a function that accepts a const char* and uses a function, ProcessString. ProcessString is a function that expects a null-terminated character buffer as a char*. The characters in the buffer may or may not be modified, as defined by the function signature below. To "bridge the gap", I am using a temporary std::string: void ProcessString( char* str ); void SomeFunction( const char* str ) { string temp(str); ProcessString( &temp[0] ); } My primary question is about the guarantees