美文网首页
warning: conversion from string

warning: conversion from string

作者: 夙小叶 | 来源:发表于2020-12-03 10:22 被阅读0次
    截屏2020-12-03 上午10.14.32.png
    class Attack
    {
        public:
            char *target_ip;
            int target_port;
    
            int run(void)
            {
                std::cout << "[*] Target IP : " << target_ip << std::endl;
                std::cout << "[*] Target Port : " << target_port << std::endl;
    
                return 0;
            }
    };
    

    警告

    class_inherit.cpp:22:23: warning: in-class initialization of non-static data member is a C++11 extension [-Wc++11-extensions]
        bool email_status = false;
                          ^
    class_inherit.cpp:40:22: warning: conversion from string literal to 'char *' is deprecated [-Wc++11-compat-deprecated-writable-strings]
        hack.target_ip = "192.168.1.101";
                         ^
    class_inherit.cpp:45:21: warning: conversion from string literal to 'char *' is deprecated [-Wc++11-compat-deprecated-writable-strings]
        web.target_ip = "192.168.1.102";
                        ^
    class_inherit.cpp:50:24: warning: conversion from string literal to 'char *' is deprecated [-Wc++11-compat-deprecated-writable-strings]
        re_run.target_ip = "10.2.2.11";
                           ^
    class_inherit.cpp:53:23: warning: conversion from string literal to 'char *' is deprecated [-Wc++11-compat-deprecated-writable-strings]
        re_run.send_email("evil@email.com");
                          ^
    5 warnings generated.
    

    虽然可以正常生成二进制文件使用,但还是看不过眼,解决方法:

    const

    const char *target_ip;
    

    使用 string 库和关键字

    #include <string>
    
    std::string target_ip;
    

    相关文章

      网友评论

          本文标题:warning: conversion from string

          本文链接:https://www.haomeiwen.com/subject/jwxmwktx.html