Flip
2004-01-19 20:38:17 UTC
im a beginer and i have a simple question. This code is an example
from my text book im trying to understand by changing it, and so far
i've been stuck at this level because i dont understand how it works.
this is a demonstration using <fstream> lib for file IO , and i dont
know the proper syntax for specifying an exact location on the HD that
i would want to save or open a file to.
in this example they are using a file called "infile.dat"..HOW can i
change this to be anything differant. I'm working on XP with Dev C++
..and lets say i wanted to save or open a file from a location in MY
Documents, it would be something like this: C:\Documents and
Settings\endALL\My Documents\File Folder
....ok, so i'll admit, i tried using an addresse with backslashes
like that and was promptly reminded that that is used to tell the
compiler that im giving it an escape sequence..
so how can i tell the compiler (in a way that it will understand)
where i want it to save and open files from?
any information appreciated!
thanks
philip
**heres the code:
#include <stdlib.h>
#include <fstream>
int main()
{
using namespace std;
ifstream in_stream;
ofstream out_stream;
in_stream.open("infile.dat");
if (in_stream.fail())
{
cout << "Input file opening failed.\n";
exit(1);
}
out_stream.open("outfile.dat");
if (out_stream.fail())
{
:
:
system("PAUSE");
return 0;
}
from my text book im trying to understand by changing it, and so far
i've been stuck at this level because i dont understand how it works.
this is a demonstration using <fstream> lib for file IO , and i dont
know the proper syntax for specifying an exact location on the HD that
i would want to save or open a file to.
in this example they are using a file called "infile.dat"..HOW can i
change this to be anything differant. I'm working on XP with Dev C++
..and lets say i wanted to save or open a file from a location in MY
Documents, it would be something like this: C:\Documents and
Settings\endALL\My Documents\File Folder
....ok, so i'll admit, i tried using an addresse with backslashes
like that and was promptly reminded that that is used to tell the
compiler that im giving it an escape sequence..
so how can i tell the compiler (in a way that it will understand)
where i want it to save and open files from?
any information appreciated!
thanks
philip
**heres the code:
#include <stdlib.h>
#include <fstream>
int main()
{
using namespace std;
ifstream in_stream;
ofstream out_stream;
in_stream.open("infile.dat");
if (in_stream.fail())
{
cout << "Input file opening failed.\n";
exit(1);
}
out_stream.open("outfile.dat");
if (out_stream.fail())
{
:
:
system("PAUSE");
return 0;
}