It's just that Stroustrup's coding style is a bit compact. Not much whitespace (at least, not as much as I'd like to leave).
And as Elysia said, main() returns 0 by default, so you don't really need to explicitly do it. The only time you have to include a return statement in main() is when you want to return a number other than 0 (to indicate an error).
And by the way, this is Stroustrup's original code (it uses std_lib_facilities.h which I posted a link to in this thread):
Code:
#include "std_lib_facilities.h"
struct Reading { // a temperature reading
int hour; // hour after midnight [0:23]
double temperature; // in Fahrenheit
};
int main()
{
cout << "Please enter input file name: ";
string iname;
cin >> iname;
ifstream ist {iname}; // ist reads from the file named iname
if (!ist) error("can't open input file ",iname);
string oname;
cout << "Please enter name of output file: ";
cin >> oname;
ofstream ost {oname}; // ost writes to a file named oname
if (!ost) error("can't open output file ",oname);
vector<Reading> temps; // store the readings here
int hour;
double temperature;
while (ist >> hour >> temperature) {
if (hour < 0 || 23 <hour) error("hour out of range");
temps.push_back(Reading{hour,temperature});
}
for (int i=0; i<temps.size(); ++i)
ost << '(' << temps[i].hour << ','
<< temps[i].temperature << ")\n";
}
Different from my coding style, especially in how he likes to put the code for an if-block on the same line as the condition there's only one small line of code.
The error code in my if-conditions should execute if something goes wrong while trying to open a file for reading or writing, right? The fact that nothing goes wrong should mean that the file exists and that the program manages to find it. So it should be that I need to make a .txt file. A .docx caused it to run the code in error().
Edit: Just now, I tried inputting the file with its path and it still had the same result as before (I did "C:\Users\Osman\Documents\temp_reading_inputfile.t xt" and "C:\Users\Osman\Documents\temp_reading_outputfile. txt").
Edit2: Why is the file extension part not coming out right in this?