J
J
Jourloy2018-05-24 23:38:47
C++ / C#
Jourloy, 2018-05-24 23:38:47

Is it possible to determine the line number in C++?

So let's say I have the following code:

cout << "Your text" << endl;
cin >> textUser;

if (textUser != "Hello")
   cout << "ERROR";

But I have a lot of such pieces with different content, respectively, there are many cases when this error is displayed, so I decided to give them a number, but in order not to take a steam bath and not look for this error, the number is the line on which they are located:
cout << "Your text" << endl;
cin >> textUser;

if (textUser != "Hello")
   cout << "ERROR [0005]";

But here I need to add text before this block, so the line number will be different.
cout << "Print hello";
cout << "Your text: " << endl;
cin >> textUser;

if (textUser != "Hello")
   cout << "ERROR [0005]"; // ?

Is there any way to keep track of the line number automatically?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
Wexter, 2018-05-24
@Jourloy

https://msdn.microsoft.com/en-us/library/b0084kay.aspx

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question