Monday, July 27, 2009

How to print the number of line in the c++ programming?

Count from the input string how many times '/n' appears. this is the number of lines for the input.


Look at the ASCII table to see how keys are being encoded.

How to print the number of line in the c++ programming?
Do you mean the line in the source code where you detected the error?





This could be done using the standard __LINE__ and __FILE__ macros.





Something like





void doSomething()


{


if (error)


{


char buffer[256] = {0};


_snprintf(buffer, 255, "Error occurred in file %s line %d\n", __FILE__, __LINE__);


}


}





the standard way to do this is to use the assert() function.


You pass it a condition to respect. If the condition is not respected it print out the failed condition and the file and line where it occurred.





Hope that help


No comments:

Post a Comment