Been working on this for a while...trying to input a text file...using windows XP
ifstream newName;
ifstream newName;
newName.open("C:\blah.txt");
if (newName.is_open())
{cout << "for the love of god";}
else
{cout << "boggle";}
newName.close();
It ALWAYS evaluates to boggle. I was using
if (newName.fail())
{cout << "hrm";}
if (newName.good())
{cout << "sweet";}
else
{cout << "boggle";}
which still evaluated to boggle. I would really appreciate help with this.
I've included both fstream and iostream...I've consulted multiple books and websites about context for ifstream and what not, to no avail. If additional info is needed to diagnose this pls let me know, I've tried both absolute path and relative path for the open...Thanks for your time.
Change the following line:
newName.open("C:\blah.txt");
To:
newName.open("C:\\blah.txt");
Damn :) This simple thing broke many keyboards )
As far as I know You can use '/' instead of '\' on win32 too.
Regards
Roman
First of all, I love you guys...worked fine after I changed the path...
Is there a way to use the relatiave path...if my text file was stored at C://blah.txt Is there a way to use just "blah.txt" when calling .open(...) ???
Thanks again for the help.
Yes relative Paths are supported but be careful: The path is normally relative to the place from where you started the programm and not to the place the executeable lies in.
Quote from: Roman on June 16, 2007, 02:13:49 PM
As far as I know You can use '/' instead of '\' on win32 too.
That's correct
*nix chdir(const char *) function
http://www.delorie.com/gnu/docs/glibc/libc_268.html
MS analog - _chdir(const char *) in <direct.h>
It seems also that BOOST::filesystem provides something portable
Regards
Roman