unable to find string literal operator ‘operator””format’ with ‘const char [10]’, ‘long unsigned int’ arguments

简介

遇到问题

unable to find string literal operator ‘operator""format’ with ‘const char [10]’, ‘long unsigned int’ arguments
 #define DEBUG_(format,...) printf("[DEBUG] "format"\n", ##__VA_ARGS__)

参考链接

https://blog.csdn.net/q2519008/article/details/80934815

Result

可能是因为C++11或者更高的标准更改了编译操作参考链接
https://en.cppreference.com/w/cpp/language/user_literal
其中" 引号也是一个可以重载的操作符。没有string和long unsigned int结合的操作符。

TODO

#define DEBUG_(format,...) printf("[DEBUG] "format"\n", ##__VA_ARGS__)

替换为宏函数

/*
 * @Author: your name
 * @Date: 2020-12-02 09:06:35
 * @LastEditTime: 2020-12-02 13:59:54
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: /my_skel/header/debug.hpp
 */
#ifndef __DEBUG_HPP__
#define __DEBUG_HPP__
#include <cstdio>
#include <string>
#include <iostream>

//#define __TT__

// #ifdef __TT__
// #define ERROR_D(...) \
// do{ \
//     fprintf(stderr, "[ERROR  ]%s %s(Line %d): ",__FILE__,__FUNCTION__,__LINE__); \
//     fprintf(stderr, __VA_ARGS__); \
// }while(0)
// #else
// #define ERROR_D(...)
// #endif

// #ifdef __TT__
// #define WARNING_D(...) \
// do{ \
//     fprintf(stdout, "[WARNING]%s %s(Line %d): ",__FILE__,__FUNCTION__,__LINE__); \
//     fprintf(stdout, __VA_ARGS__); \
// }while(0)
// #else
// #define WARNING_D(...)
// #endif


// #ifdef __TT__
// #define INFO_D(...) \
//     do{ \
//         fprintf(stdout, "[INFO  ]%s %s(Line %d): ",__FILE__,__FUNCTION__,__LINE__); \
//         fprintf(stdout, __VA_ARGS__); \
//     }while(0)
// #else
// #define INFO_D(...)
// #endif


#ifdef __TT__
#define DBG_D(format,...)\
do{ \
    std::string tout_xxdafdsaf="[DEBUG] "; \
    tout_xxdafdsaf += (std::string)format; \
    printf(tout_xxdafdsaf.c_str(), ##__VA_ARGS__); \
}while(0)
#else
#define DBG_D(format,...) \
    do{ \
    }while(0)
#endif


#ifdef __TT__
#define DBG_S(...)\
do{ \
    std::cout << __VA_ARGS__; \
}while(0) 
#else
#define DBG_S(...) \
    do{ \
    }while(0) 
#endif


// #ifdef __TT__
// #define SHOW_TIME(...) \
// do{\
//     extern unsigned long long gLatestTime;\
//     timeval tp;\
//     gettimeofday(&tp, NULL);\
//     unsigned long long now = tp.tv_sec*1000000+tp.tv_usec; \
//     if(gLatestTime != 0) \
//     { \
//         fprintf(stdout, ">>>>>>>>>Used Time: %s[%d], %s: %ld.%ld, %llu ms ", __FILE__, __LINE__, __func__, tp.tv_sec, tp.tv_usec, (now-gLatestTime)/1000);\
//         fprintf(stdout, "/n"); \
//     } \
//     gLatestTime = now;\
// }while(0)  
// #else
// #define SHOW_TIME(...)
// #endif

#endif

因为宏展开防止出现同名 使用了tout_xxdafdsaf这个

原文链接: https://www.cnblogs.com/eat-too-much/p/14072090.html

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍

    unable to find string literal operator ‘operator""format’ with ‘const char [10]’, ‘long unsigned int’ arguments

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/205677

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年2月12日 下午10:19
下一篇 2023年2月12日 下午10:19

相关推荐