如何有效地复制 std::vector到 std::string
这个问题是这个问题的另一面 如何有效地复制 std ::字符串转换为向量 我通常以这种方式复制向量(空终止字符串) std::string s((char*)&v[0]); 或(…
如何有效地将 std::string 复制到向量中
我有一个字符串 std::string s = "Stack Overflow"; ,我需要将其复制到向量中。 我就是这样做的 std::vector v; v.reserve(s.length()+1); for(std::…
如何有效地从 std::string 中删除双引号(如果存在)
这个问题有重复的风险,例如 remove doublequotes from a string in c++ 但我看到的答案都没有解决我的问题 我有一个字符串列表,其中一些是双引号的…
编译器通常对字符串有特殊的优化吗?
很多时候,您会看到类似 std::map m_named_objects; 或 std::string state; //... if(state == "EXIT") exit(); else if(state == "california") hot(…
如何为具有内部放置 new 的类实现安全复制构造函数(使用 std::string)
这是我的代码: struct RS_Token { char id; char cleanup; unsigned char array[sizeof (std::string) > sizeof (double) ? sizeof (std::string) : …
C++:将 std::string 传递给想要更改字符串的 C 函数的正确实现?
我在用 C 编写的第三方库中有一个函数:char* fix_filename_slashes(char* path)。此函数需要传递给它的可变 C 字符串,以便它可以根据操作系统将路径…
绑定到函数的指针只能用于调用函数
我刚刚从 char 数组转移到 std::string 并且已经遇到了问题,我可能正在做一些非常愚蠢的事情,请随意嘲笑: int main() { string * p = new string; …
std::string::back()
为什么没有 std::basic_string::back() 成员函数? 功能显然是存在的,我的意思是,可以编写 myString[myString.size()-1] *myString.rbegin() 我是否…
C++ std::basic_string/char_traits 专业化
这与: std::basic_string 专业化 和 规避模板专业化 我尝试了 std::basic_string 专业化,但问题是 CustomChar 是 wchar_t 的 typedef 并且我有重新…
NSString 弱持有 std::string 的 const char *
NSString 弱包含属于 std::string 的 const char * 最安全的方法是什么?下面的两个示例都适用于日志中的简单测试,并如 NSTableView 中所示,但我担…
C++/CLI 字符串转换
我发现这段非常好的代码将字符串转换为 System:String^ ,如下所示: System::String^ rtn = gcnew String(move.c_str()); // 'move' here is the str…
MFC:std::string 与 CString?
将 C++ 与 MFC 结合使用。由于具有 C# 背景,我通常只使用 string 来表示所有字符串。我将它们用于类成员、方法参数和方法返回值。 现在,在 C++ 中,…
C++如何计算字符串在数据中出现的次数
我想测量以下两件事: 逗号出现在 a 中的次数 std::std,例如如果 str ="1,2,3,4,1,2," 如果出现上述情况,则 str.Count(',') 返回我 6 string 第二件…
在 C++ 中比较 std::string 与常量与比较 char 数组与常量
我正在尝试进行一些文本冒险来掌握 C++。 cin >> keyboard1; if ((keyboard1 == "inv")inventory(inv); 如果 Keyboard1 是字符串,则这将起作用,但如…
在 boost 中,如何将 boost 迭代器传递给以某种方式转换为 std::string 的函数
请参阅以下代码末尾的注释作为具体问题。 std::string s("my sample string \"with quotes\""); boost::escaped_list_separator els(""," ","\"\'"); …