从'const char *'到'char *'的无效转换[-fpermissive] [英] invalid conversion from ‘const char*’ to ‘char*’ [-fpermissive]

查看:960
本文介绍了从'const char *'到'char *'的无效转换[-fpermissive]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

int ::  cadena calculatelenght(const cadena& a, const char* cad)
{
    cadena c;
    int lenght = 0;
    char* punt; punt = cad;
    while(*punt){
        lenght++; punt++;
    }
    return lenght;
}

我有这个问题,我想计算一个C字符串的长度,使用函数 strlen ,在我的cadena类的其他方法我可以,因为不是const char *,但现在我不知道该怎么办。

I have this problem, I want to calculate the length of a C string without using functions like strlen, in other methods of my cadena class I can because is not const char*, but now I don't know what to do.

推荐答案

您可以将 punt 声明为正确的类型:

You can declare punt to be of the correct type:

const char * punt = cad;

这篇关于从'const char *'到'char *'的无效转换[-fpermissive]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆