草庐IT

function_char-length

全部标签

char 指针上的 C++ 错误

我想在结构中初始化一个char*字符串。这是结构:typedefstruct__String{char*data;//C-stringdata,unsigned*copyRef;//numberofcopyreference,deleteonlywhenthecopyRefis0boolisACopy;//thisbooleanistruewhen*dataisareftoanotherMyString__String(){data=0;isACopy=false;copyRef=newunsigned();*copyRef=0;return;}voidaddCopyRef(){*co

c++ - "Function not declared in this scope"编译openCV代码出错

我正在尝试编写一些使用openCV函数的代码。我从文档中提供的一些示例代码开始:#include#include#includeusingnamespacecv;usingnamespacestd;intmain(intargc,char**argv){if(argc!=2){cout当我尝试在Eclipse-CDT中构建它时,我得到了这个:****BuildofconfigurationDebugforprojectopenCV1****makeallBuildingtarget:openCV1Invoking:CrossG++Linkerg++-L/usr/local/lib-o"

c++ - 海湾合作委员会 "no matching function for call.."错误

我正在开发一个跨平台代码库,其中初始工作是使用MSVC2010编译器完成的。后来我在Linux上使用GCC(4.7)编译它。在许多情况下,我收到:“没有匹配的调用函数..”GCC中的错误。我注意到它主要在方法参数是非常量引用时提示。例如:voidMyClass::DoSomeWork(ObjectSP&sprt,conststd::stringsomeName,conststd::stringanotherName,conststd::stringpath,intindex){sprt->GetProp()->Update(path,false);}一旦我将方法更改为:voidMyCl

c++ - 从自定义 printf 函数返回 const char*

我编写了一个自定义打印函数。我的问题是我需要返回一个constchar*,因为它必须在另一个函数中使用。我根本不知道如何管理...anotherFunction(constchar*text/*Here*/,unsigned__int32value,unsigned__int64bigVal);我知道以下示例无法正常工作。这就是我到目前为止所尝试的。constchar*CatchMessage(constchar*message,...){va_listargs;va_start(args,message);/*?*/va_end(args);returnmessage;}我目前只设法

c++ - 类型为 "const char *"的值不能分配给类型为 "char"的实体 C OOP

我正在创建一个类来计算C++用户的成绩,我遇到了一个简单但烦人的问题。我知道这些错误是什么意思,但我不明白如何修复它,更改为字符串实际上可以解决问题,但这不是我想要做的。这里是错误:constchar*"cannotbeassignedtoanentityoftype"char代码#includeusingnamespacestd;classGradecalc{public:Gradecalc(){mark=0;}intgetmark(){returnmark;}voidsetmark(intinmark){mark=inmark;}voidcalcgrade(){if(mark>=7

c++ - visual studio 中涉及 void*、string 和 const char[] 的意外重载解析

我在visualstudio编译器(在VS2010和VS2012中测试)中遇到了以下意外的重载解析行为。最小的例子:#include#includevoidf(void*){std::cout输出:>f(void*)预期输出:>f(conststd::string&)用GCC编译(用4.6.3测试)生成预期的输出。如果我注释掉f()的“conststd::string&”版本,visualstudio会在没有任何警告的情况下愉快地在/W4上编译,而GCC会发出以下错误(如预期的那样):“来自'constvoid的无效转换*'到'void*'[-fpermissive]”。有谁知道为什么

c++ - 在 C++ 中有没有办法从不同的内存位置打印 char*?

我不确定这个问题是否有意义,所以我将尝试展示一个例子:想象一下,我在内存位置&s处有一个字符串(未以空值终止),在内存位置z处有另一个字符串(以空值终止)。chars[4];s[0]='a';s[1]='a';s[2]='a';s[3]='a';char*z=malloc(sizeof(char)*4);z[0]='a';z[1]='a';z[2]='a';z[3]='\0';char*y=malloc(sizeof(char)*4);y[0]='a';y[1]='a';y[2]='a';y[3]='\0';有没有办法表示字符串u,即s和z与另一个字符串的串联v,这是s和y的串联,而无

c++ - 指针,将 char ** 转换为 char *

我正在研究指针,但我被下面的示例程序难住了。它应该是将char**转换为char*,但我不明白程序背后的逻辑。程序在做什么?#includeusingnamespacestd;intmain(){char*notes[]={"cpp","python","java","mariadb"};void*base=notes;//notesandbase,holdstheaddressofnote'sfirstelementvoid*elemAddr=(char*)base+3*sizeof(char*);//ididn'tunderstandthisline???cout

c++ - 使用 std::function 参数重载函数:为什么从未调用 const 方法?

#include#include#include#includeusingnamespacestd;classA{public:voiddoStuff(functionfunc)const{coutfunc){cout(str);func(mutableString);});}private:vectorm_vec;};intmain(){autoa=A{};a.doStuff([](string*str){*str="Imodifiedthisstring";});}在此示例中,从未调用const方法。如果代码看起来很奇怪,这就是我正在尝试做的事情:我让客户通过传递一个函数来迭代对象

C#的Char 结构的像IsLetterOrDigit(Char)等常见的方法

 目录一、Char结构的方法二、Char.IsLetterOrDigit方法1.Char.IsLetterOrDigit(Char)用法2.IsLetterOrDigit(String,Int32)方法三、Char.IsLetter方法1.IsLetter(Char)2.IsLetter(String,Int32)四、Char.IsDigit方法1. IsDigit(String,Int32)2.IsDigit(Char)五、Char.IsLower方法1. IsLower(Char)2.IsLower(String,Int32)六、Char.IsNumber方法1. IsNumber(Str