How can I use the compile time constant __LINE__ in a string?

后端 未结 8 2061
旧巷少年郎
旧巷少年郎 2021-01-31 10:41

I can use __LINE__ as a method parameter just fine, but I would like an easy way to use it in a function that uses strings.

For instance say I have this:

8条回答
  •  被撕碎了的回忆
    2021-01-31 11:17

    Try this?

    string myTest(const int lineno)
    {
      if(!testCondition)
        return logError ("testcondition failed", lineno);
    }
    
    void logError (string msg, const int lineno)
    {
      clog << "line " << lineno << ": " << msg << endl;
    }
    

提交回复
热议问题