Hi, I've been reading B. Stroustrup's FAQ and found
How do I write this very simple program?
What is interesting is this sentece:
I test it on my Dev-Cpp compiler with this codeThe program ends reading input when it sees "end of file". If you run the program from the keybord on a Unix machine "end of file" is Ctrl-D. If you are on a Windows machine that because of a bug doesn't recognize an end-of-file character, you might prefer this slightly more complicated version of the program that terminates input with the word "end":
And after entering Ctrl-Z I saw line "Test is OK".Code:#include<iostream> #include<vector> #include<algorithm> using namespace std; int main() { vector<double> v; double d; while(cin>>d) v.push_back(d); // read elements if (!cin.eof()) { // check if input failed cerr << "format error\n"; return 1; // error return } if(cin.eof()) { cout<<endl<<"Test is OK"<<endl; } cout << "read " << v.size() << " elements\n"; reverse(v.begin(),v.end()); cout << "elements in reverse order:\n"; for (int i = 0; i<v.size(); ++i) cout << v[i] << '\n'; return 0; // success return }
Can you comment this?
I'd like to read your opinion on this.
Cheers!
Micko