[Dev-C++] Question about working directory in Win2k
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: David M. <dml...@co...> - 2004-06-22 00:20:06
|
When I run the following program on win2k pro it has no problem finding
the input file because when I drag a file on to it windows gives it the
absolute filename. The problem is the executable & the input file are in
a folder on the E drive and the output file is written to c:\Documents
and Settings\david\ . Why do I have to specify the absolute filename
just to get the working directory to the one as the executable? I have
an explorer window open to e:\primes and I drag the input file onto the
executable's icon. The program shows no errors, the output is just in
the wrong place. Any simple way to fix?
#include <iostream>
#include <algorithm>
#include <iterator>
#include <fstream>
#include <iomanip>
#include <cstdio>
using namespace std;
char tmp_file[] = "1234.txt";
int main(int argc, char *argv[])
{
if(argc == 2)
{
cout << "Opening " << argv[1] << endl;
ifstream read_from(argv[1]);
ofstream write_to(tmp_file);
int temp, count = 0;
while(!read_from.eof())
{
read_from >> temp;
write_to << temp << endl;
count++;
}
read_from.close();
write_to.close();
//remove(argv[1]);
//rename(tmp_file, argv[1]);
cout << "Done." << count << endl;
}
else
{
cout << "Invalid number of arguments\n";
}
cin.get();
}
|