I'm trying to use files, but have an error.
Code:
#include <iostream>
#include <fstream>
using namespace std;
int main(int argc, char *argv[]) {
if(argc != 3) {
cout << "Usage: cpp <infile (.cpp)> <outfile (.html)>" << endl;
return 1;
}
ifstream in(argv[1], (ios::in | ios::trunc));
if(!in.is_open()) {
cout << "Error opening '" << argv[1] << "'." << endl;
return 1;
}
ofstream out(argv[2], ios::out);
if(!out.is_open()) {
cout << "Error opening '" << argv[2] << "'." << endl;
return 1;
}
in.close();
out.close();
}
I ran the program with the command line: "cpp one.cpp out.html" where one.cpp and out.html are files that are in the same directory, but I always get "Error opening 'out.cpp'." Anyone got any ideas? Thanks !