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

Posted by John on Stack Overflow See other posts from Stack Overflow or by John
Published on 2010-04-19T20:56:19Z Indexed on 2010/04/19 21:23 UTC
Read the original article Hit count: 221

Filed under:
|
|

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:

11    string myTest()
12    {
13     if(!testCondition)
14       return logError("testcondition failed");
15    }

And I want the result of the function to be:

"myTest line 14: testcondition failed"

How can I write logError? Does it have to be some monstrosity of a macro?

© Stack Overflow or respective owner

Related posts about c++

Related posts about preprocessor