#include <stdio.h>
int main()
{
    const int a = 12;
    int *p;
    p = &a;
    *p = 70;
}
它会起作用吗?
可能重复:
如何摆脱deprecated conversion from string constant to ‘char*’海湾合作委员会的警告?
我使用库中的以下功能,我无法改变:
HRESULT DynamicTag(char * pDesc, int * const pTag ); 
我用它如下.我创建了实现上述函数的库提供的类的对象.
int tag =0;
g_pCallback->DynamicTag("MyLogger", &tag);
我收到以下警告:
warning: deprecated conversion from string constant to 'char*'
摆脱上述警告的最佳方法是什么?我不想动态分配内存.
信息:我正在使用Vxworks6.8编译器
可能重复:
如何摆脱deprecated conversion from string constant to ‘char*’海湾合作委员会的警告?
这项任务:
char *pc1 = "test string";
给了我这个警告:
警告:不推荐将字符串常量转换为'char*'
虽然这个似乎很好:
char *pc2 = (char*)("test string");
这是一个真正更好的方法吗?
注意:由于其他原因我不能使用const char*.
我正在使用字符串.
每当我执行下面的程序时,我都会收到一个错误,因为在行中c*的字符串常量被转换为'char 'char *p = "hello"
我究竟做错了什么?
这个错误是什么意思?我怎么能纠正它?
我的代码是:
#include<stdio.h>
int main()
{
    char *p = "hello";
    printf("%s",p+1);
    return 0;
}
我的项目中有一些不赞成使用的常量.他们需要留下来.我不想被警告他们,但是如果其他已弃用的常量稍后会出现在我的项目中,我们希望得到警告.
Apple的标题声明如下:
extern NSString * const NameOfStringConstant __OSX_AVAILABLE_BUT_DEPRECATED(version availability info here)
我怎样才能使警告静音?
是否有#pragma覆盖编译时警告,例如:
warning: 'ADBannerContentSizeIdentifier480x32' is deprecated (declared at /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.2.sdk/System/Library/Frameworks/iAd.framework/Headers/ADBannerView.h:111)
我必须通过以下方式保持4.2之前iOS设备的兼容性:
NSString *iAdSize = (osVersion >= 4.2) ? ADBannerContentSizeIdentifierPortrait : ADBannerContentSizeIdentifier480x32;
谢谢
错误的位置在下面的注释中指出.请帮忙解决这个问题.
#include<iostream.h>
#include<string.h>
#include<stdlib.h>
class String
{
private:
    enum{sz=80};
    char str[sz];
public:
    String()
    {
        strcpy(str,"");
    }
    String (char s[])
    {
        strcpy(str,s);
    }
    void display() const
    {
        cout<<str;
    }
    String operator +(String ss) const
    {
        String temp;
        if(strlen(str) + (strlen(ss.str) < sz)
        {
            strcpy(temp.str,str);
            strcat(temp.str , ss.str);
        } // Error is reported here!
        else
        {
            cout<<"\nstring overflow";
            exit(1);
        }
        return temp;
    }
};
int main()
{
    String s1="\nMerry christmas";
    String s2="happy new year";
    String s3;
    s1.display();
    s2.display();
    s3.display();
    s3=s1+s2;
    s3.display();
    cout<<endl; …可能重复:
C++不推荐将字符串常量转换为'char*'
我有以下代码,虽然我没有复制完整的代码,因为它是巨大的.以下代码在模板类中,我收到如下警告.由于模板中的警告,我无法实例化它并从此处"实例化"错误.
警告:已弃用从字符串常量转换为'char*''
void ErrorMessageInRaphsodyCode(char* pcCompleteMessage, char* pcMessage, char* pcFileName, unsigned int RowNo)
{
//...
}
char cCompleteMessage[200];
memset(cCompleteMessage, 0x00, sizeof(cCompleteMessage));
char*cMessage = "add reorgenize failed";
ErrorMessageInRaphsodyCode(cCompleteMessage, cMessage, "omcollec.h", __LINE__);
我的问题是什么是摆脱上述警告的最佳方法?
c++ ×4
c ×2
objective-c ×2
xcode ×2
char ×1
coding-style ×1
const ×1
deprecated ×1
iphone ×1
literals ×1
pointers ×1
string ×1
warnings ×1