R
Ramon F Herrera
I am running the examples included in the book "Thinking in C++" (*).
This one has a a problem:
//: C02:Scopy.cpp
// Copy one file to another, a line at a time
#include <string>
#include <fstream>
using namespace std;
int main() {
ifstream in("Scopy.cpp"); // Open for reading
ofstream out("Scopy2.cpp"); // Open for writing
string s;
while(getline(in, s)) // Discards newline char
out << s << "\n"; // ... must add it back
} ///:~
The version above works fine, creating a copy of its own source code.
However, if I add this
exit (0);
statement at the end, an empty file is created instead.
Is it supposed to work that way?
-Ramon
(*) highly recommended, available for free.
This one has a a problem:
//: C02:Scopy.cpp
// Copy one file to another, a line at a time
#include <string>
#include <fstream>
using namespace std;
int main() {
ifstream in("Scopy.cpp"); // Open for reading
ofstream out("Scopy2.cpp"); // Open for writing
string s;
while(getline(in, s)) // Discards newline char
out << s << "\n"; // ... must add it back
} ///:~
The version above works fine, creating a copy of its own source code.
However, if I add this
exit (0);
statement at the end, an empty file is created instead.
Is it supposed to work that way?
-Ramon
(*) highly recommended, available for free.