Nagging Quesions
There are several issues that have been bothering me lately and I want to ask you all about them.
1.) What's the point of 'cerr' when 'cout' does the same thing?
2.) Do you need to put .f to make a floating-point number single precision rather than double? I've heard that by default floating-point numbers are double, even if you declare them:
float number = 1.5;
To make this single precision, you need to declare it like:
float number = 1.5f;
Is this true?
3.) When dealing with file I/O, what's the point of 'ios::out' and 'ios::in' if the user already uses 'ofstream' or 'ifstream'?
What would the following do:
ofstream output(filename, ios::in);
4.) void main() vs. int main() . I know that the standard is moving toward int main() , but why? Just because you stick the return 0; statement at the end of the program, doesn't make it run any differently than void main() .
That's all for now. Please respond to any and all comments.
---
Joker2000
Stevie Ray Vaughan - The Legend
Edited by - Joker2000 on 8/2/00 8:41:57 PM
Edited by - Joker2000 on 8/2/00 8:42:50 PM
---Joker2000Stevie Ray Vaughan - The Legend
.Hi Joker, been meaning to get back to you.
cout and cerr correspond to standard output and standard error, in unix it's common to redirect standard output to a log file or /dev/null and run a program in the background. In this case everything written to cout will go where it's redirected, but you will get anything written to cerr (presumably an error) sent to the screen, or your program will be put to sleep and a message notifying you that you have tty output will be displayed. cerr is also unbuffered, but don't use it for that as it's a bad habit if you ever wind up coding for a "real os".
You almost never need to put f after a literal, these numbers are promoted/demoted automagically.
ofstream and ifstream are almost identical under the hood, though if you want to do something fancy you should probably use fstream, particularly if you want a file open for reading and writing.
the standard is, and always has been int main(). The return value from main is the value returned to the parent process when your process terminates. This is true even in dos, though the only place it's ever used is in %ERRORLEVEL% in .BAT files. In most unix shells it's often useful to say "do this, and if it worked, do something else" or do something else if the first program ended with an error. Note that exit() also requires a value to be returned to the parent process.
Edited by - Grib on August 2, 2000 10:41:03 PM
cout and cerr correspond to standard output and standard error, in unix it's common to redirect standard output to a log file or /dev/null and run a program in the background. In this case everything written to cout will go where it's redirected, but you will get anything written to cerr (presumably an error) sent to the screen, or your program will be put to sleep and a message notifying you that you have tty output will be displayed. cerr is also unbuffered, but don't use it for that as it's a bad habit if you ever wind up coding for a "real os".
You almost never need to put f after a literal, these numbers are promoted/demoted automagically.
ofstream and ifstream are almost identical under the hood, though if you want to do something fancy you should probably use fstream, particularly if you want a file open for reading and writing.
the standard is, and always has been int main(). The return value from main is the value returned to the parent process when your process terminates. This is true even in dos, though the only place it's ever used is in %ERRORLEVEL% in .BAT files. In most unix shells it's often useful to say "do this, and if it worked, do something else" or do something else if the first program ended with an error. Note that exit() also requires a value to be returned to the parent process.
Edited by - Grib on August 2, 2000 10:41:03 PM
I can answer some of these for you
1) in DOS cerr and cout are the same. cerr outputs to standered error (wich happens to be the same place cout puts stuff (the console)). cout puts it on the standered out(the console/screen)... under unix you can direct it to a file or just about anything else....
2)I don''t now for sure...
3)I''m not realy sure on this one eather =) maybe to lock it into eatehr I or O....
4) the int version will return the exit code to the OS where the void always returns 0... I don''t know the actual numbers for them but you could return a vaule that means "Normal Exit"0, "Abort", "General Protection", "What ever" with the int main(void)... under dos it makes no diffrence... I''m not realy sure on unix... or any of the others for that mater=) but thats what it is supose to be used for...
Great Milenko
1) in DOS cerr and cout are the same. cerr outputs to standered error (wich happens to be the same place cout puts stuff (the console)). cout puts it on the standered out(the console/screen)... under unix you can direct it to a file or just about anything else....
2)I don''t now for sure...
3)I''m not realy sure on this one eather =) maybe to lock it into eatehr I or O....
4) the int version will return the exit code to the OS where the void always returns 0... I don''t know the actual numbers for them but you could return a vaule that means "Normal Exit"0, "Abort", "General Protection", "What ever" with the int main(void)... under dos it makes no diffrence... I''m not realy sure on unix... or any of the others for that mater=) but thats what it is supose to be used for...
Great Milenko
Words Of Wisdom:
"Never Stick A Pretzel In Your Butt It Might Break Off In There."
http://www.crosswinds.net/~milenko
http://www.crosswinds.net/~pirotech
The Great Milenko"Don't stick a pretzel up your ass, it might get stuck in there.""Computer Programming is findding the right wrench to hammer in the correct screw."
cerr and cout (stderr and stdout) are _not_ the same. They are different files, but the usually print out to the screen by default. Error messages are supposed to go in cerr, so you can redirect it to an error log file for example (or send cout to /dev/null and let cerr print to the screen as Grib pointed out).
Btw, you can redirect stdout under DOS too: dir > listing.txt (didn't know that until yesterday btw ). Don't know about the other std-files though.
Edited by - Muzzafarath on August 3, 2000 6:20:22 AM
Btw, you can redirect stdout under DOS too: dir > listing.txt (didn't know that until yesterday btw ). Don't know about the other std-files though.
Edited by - Muzzafarath on August 3, 2000 6:20:22 AM
I'm reminded of the day my daughter came in, looked over my shoulder at some Perl 4 code, and said, "What is that, swearing?" - Larry Wall
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement