473,378 Members | 1,496 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

cout and perror

In one of my applications, I was mixing perror (cerrno )with
cout(iostream) calls and sometimes getting unordered output. The exact
context was to print an error condition as well as cause for
exceptions. Therefore, I resorted to .flush call in iostream that did
the trick. Anyone can explain the root of all evil in intermixing the
c++ with date c library, perhaps, give a link to where solutions to
this problem are addressed?
Why don't file related exception don't have a error message that would
indicatate the exact reason for a failure and stack trace?
Thanks

Oct 22 '05 #1
3 3050
puzzlecracker wrote:
In one of my applications, I was mixing perror (cerrno )with
cout(iostream) calls and sometimes getting unordered output. The exact
context was to print an error condition as well as cause for
exceptions. Therefore, I resorted to .flush call in iostream that did
the trick. Anyone can explain the root of all evil in intermixing the
c++ with date c library, perhaps, give a link to where solutions to
this problem are addressed?
Well googling for "mixing cout and printf" yields some pretty good
results. Is it so hard to search a bit before asking a question?
Why don't file related exception don't have a error message that would
indicatate the exact reason for a failure and stack trace?


Because the "exact reason" can be pretty much anything because a C++
application can run on pretty much anything. It is impossible to have
error codes for every possible error, that's why it depends on the
implementation.

As for having error messages, I much prefer as a developper to have an
error code than a message. What about internationalization, for
example?

If it is only for debugging, most compilers will provide some ways to
retrieve error messages on a system (such as GetLastError() and
FormatMessage() on Win32), but since these are non-standard, you should
ask on a newsgroup supporting your implementation.
Jonathan

Oct 22 '05 #2
puzzlecracker wrote:
In one of my applications, I was mixing perror (cerrno )with
cout(iostream) calls and sometimes getting unordered output. The exact
context was to print an error condition as well as cause for
exceptions. Therefore, I resorted to .flush call in iostream that did
the trick. Anyone can explain the root of all evil in intermixing the
c++ with date c library, perhaps, give a link to where solutions to
this problem are addressed?
Why don't file related exception don't have a error message that would
indicatate the exact reason for a failure and stack trace?
Thanks


Use strerror(). That way you can format your output more precisely anyways.
Oct 22 '05 #3

"puzzlecracker" <ir*********@gmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...


Why don't file related exception don't have a error message that would
indicatate the exact reason for a failure and stack trace?


In this case boost is a must:
http://www.boost.org/libs/iostreams/...xceptions.html

Greetings, Bane.
Oct 23 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
by: qazmlp | last post by:
I hope comp.lang.c will not find the following question as a complete off-topic. I would like to remove ie.comment out the 'cout' statements during compilation(actually preprocessing) time. ...
5
by: Mastupristi | last post by:
I want to obtain the c++ equivalent of: unsigned short us = 347; printf("0x%04hX",us); that outputs "0x015B" I ried with: cout.setf(ios_base::hex,ios_base::basefield);
5
by: L. Westmeier | last post by:
Reading the man pages and some code did not really help me in understanding the difference between - or better when I should use - perror("...") and fprintf(stderr, "...") Any hint or help is...
7
by: Martin | last post by:
My program cored and the following is the call stack in dbx. I would like to know what are the possibilities that when perror is being called, it will core? dbx: warning: cannot get thread count...
1
by: Clunixchit | last post by:
Im writing a program in which i have to perform several mallocs in order to simply my code i have used void e_malloc(){ perror("malloc"); _exit(EXIT_FAILURE); } if ( !(phrase.T = malloc (...
10
by: nuke1872 | last post by:
Hello guys, I have a file names network.txt which contains a matrix. I want to read this matrix as store it as an array. I am new to stuff like these...can anybody help me out !! Thanks nuke
10
by: Guillaume Dargaud | last post by:
Hello all, I have some error checking using the function 'perror', which writes messages on stderr. I'd like to send all error messages to a file instead. Is there some way to do this, short of...
58
by: Mark Casternoff | last post by:
I'm getting back into C++ after a long hiatus (they didn't have namespaces back then). I know this question is completely subjective, but I'd be interested in hearing which is the "better"...
1
by: William Chavula | last post by:
void basic() { cout<<"---FOLLOW THESE STEPS TO DIAGNOSE INTERNET PROBLEMS---\n\n"; cout<<"---STEP 1---\n\n"; cout<<"Run your mobile partner software\n\n"; cout<<"---STEP 2---\n\n";...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.