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這個


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM