PCCP Demo

Jan 06, 2005 11:40

WoW! The code worked finally ( Read more... )

Leave a comment

Comments 3

code_martial January 6 2005, 07:25:21 UTC
Lessons learnt, it's high time i should start using debugger, no more cout, printf.

Partly right, partly wrong. The right part is is that you shouldn't use cout or printf. The wrong part is that you should use a debugger instead. Use cerr or fprintf(cerr, ...). The best use of a debugger is for locating the point of a segfault:

$ gdb ./my_exe core
(gdb) bt
For string conversions,

string str;
char * foo = const_cast(str.c_str()); // Safe, since c_str() returns a copy
const char * bar = str.c_str();
Also see this: http://www.awprofessional.com/articles/article.asp?p=21853

Reply

code_martial January 6 2005, 07:40:10 UTC
Oops! I got your problem wrong. Do this:

char dest[BUFSIZ];
string source = "foo";
strncpy(dest, source.c_str(), BUFSIZ);

Reply


bluesmoon January 6 2005, 08:36:42 UTC
Never underestimate the power of print statements for debugging
- The elements of programming style.

Written by the Gods themselves.
Use a debugger, but never stop using print statements for debugging. Also consider using cerr or fprintf(stderr, ...) instead of cout and printf. It's easier to separate your debugging output from regular output using redirection:

$ foo 2>debug.log

will direct your debugging output to debug.log

- Philip (former PCCPfac)

Reply


Leave a comment

Up