草庐IT

string-comparison-functions

全部标签

c++ - g++ "declaration of "运算符<<"as non-function"

我们有一个自定义的Logging类,它在VisualStudio2010中编译良好,但在Linux上使用g++编译时会抛出错误。我们收到的错误消息如下:Logger.hpp:84:error:declarationof"operator各自的代码行如下:/*:84*/inlineLogger&operatoroutput){if(this->loggingEnabled())std::coutoutput){if(this->loggingEnabled())std::cout>&(*StdEndl)(std::basic_ostream>&);inlineLogger&operato

c++ - 如何将 char 数组放入 std::string

我分配了一个char数组然后我需要将它作为一个字符串返回,但我不想复制这个char数组然后释放它的内存。char*value=newchar[required];f(name,required,value,NULL);//fillthearraystrResult->assign(value,required);delete[]value;我不想像上面那样做。我需要将数组放在std字符串容器中。我该怎么做?编辑1:我知道我不应该这样做,并且该字符串不是为此目的而设计的。MB有人知道我可以使用的char数组的另一个容器实现吗? 最佳答案

c++ - emacs - 如果函数包含在命名空间中 (C++),则 "go to beginning of the function"不起作用

在emacs中,我使用C-M-a和C-M-e来开始/结束C++代码中的函数。但是,如果函数包含在命名空间中(它只是跳转到命名空间封装的开头或结尾),则此功能不再有效。有人对此有好的解决方案吗? 最佳答案 这是一个已知错误。它已在Emacs24.1中得到修复,即releasedthreedaysago.得到它。不幸的是,该修复程序从未向后移植,并且不太可能很快发生。 关于c++-emacs-如果函数包含在命名空间中(C++),则"gotobeginningofthefunction"不起作

c# - __declspec(dllexport)::vector <std::string>

我一直在努力弄清楚如何将字符串数组从C++DLL返回到C#应用程序,但我对如何执行此操作或在非常基础的级别上查找文章感到困惑。假设我有下面的代码。如何修复粗体线:extern"C"{__declspec(dllexport)intGetANumber();//unsureonthisline:**__declspec(dllexport)::vectorListDevices();**}extern::vectorGetStrings(){vectorseqs;returnseqs;}externintGetANumber(){return27;}谢谢马特

c++ - swig 对基类 'std::string' 一无所知,忽略

我正在尝试使用swig围绕C++库构建ruby​​包装器。其中大部分似乎都有效,但我有一个问题,我很确定与上述警告有关。看起来我正在包装的类之一是从std::string继承的。我在运行swig时看到上面的警告消息。当我在应该返回字符串的ruby​​对象上调用方法时,我看到了这个SWIG::Type_p_std__string:0x.....我在想我需要解决上面的警告,让它起作用,有什么想法吗? 最佳答案 SWIG提示它不知道std::string类,因此无法为其生成代码。SWIG库std_string.i具有用于将C++字符串映射

c++ - 什么时候在 C++ 程序的开头使用 '#include <string>'?

我对#include的使用感到困惑在程序的开始。例如,在下面的代码中,我不使用#include但该函数在运行时仍会打印出字符串“Johnny'sfavoritenumberis”。#includeusingnamespacestd;voidprintVariable(intnumber){cout但是,在下面的代码中,它确实包含#include.#include#includeusingnamespacestd;classVar{public:voidsetName(stringx){name=x;}stringgetName(){returnname;}private:stringn

c++ - 从 std::stringstream 传递 std::string 引用作为参数

我正在使用std::stringstream构造一个字符串,然后尝试将完成的字符串作为对函数的引用传递,该函数将std::string&作为参数。我在GCC上遇到编译错误:../src/so.cpp:22:21:error:invalidinitializationofnon-constreferenceoftype‘std::string&{akastd::basic_string&}’fromanrvalueoftype‘std::basic_stringstream::__string_type{akastd::basic_string}’../src/so.cpp:12:6:e

c++ - 采用 `std::string` 的显式构造函数得到 `char*` 并且工作正常

将StringBuilder构造函数标记为显式我想我不能传入char*但似乎我可以,因为它编译得很好。classStringBuilder{public://StringBuilder(constchar*);explicitStringBuilder(std::strings){}};intmain(){StringBuilders1("hello");StringBuilders2(std::string("hello"));}http://cpp.sh/6uomq 最佳答案 basic_string采用字符指针的构造函数不是e

c++ - 为什么 std::function 在这种情况下不起作用?

假设我有一个类型:structmy_type{doubleoperator()(inta){return3.1415;}};然后我想将它包装在std::function中。考虑两种不同的方法:my_typem_t;std::functionf(std::move(m_t));std::cout一切如我所料,打印出了PI的第一位数字。然后第二种方法:std::functionff(my_type());std::cout在我看来,这段代码与第一个代码绝对相同。rvalue作为参数传递给function包装器。但问题是,第二个代码无法编译!我真的不知道为什么会这样。

c++ - 由于对具有 std::string 的方法的 undefined reference ,链接 webrtc-native 时出错

我正在尝试构建webrtc版本62,使用以下内容1.gitcheckout-bbranch62refs/remotes/branch-heads/622.gngenout_release_62/x64/Debug--args="rtc_include_tests=falsertc_use_h264=falseuse_rtti=trueis_component_build=falseenable_iterator_debugging=falseenable_nacl=falsetarget_os=\"linux\"target_cpu=\"x64\"is_debug=true"3.nin