News:

Accounts with zero posts and zero activity during the last months will be deleted periodically to fight SPAM!

Main Menu

fstream issues

Started by slightlyeskew, June 16, 2007, 12:11:41 PM

Previous topic - Next topic

slightlyeskew

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.

Biplab

Change the following line:
newName.open("C:\blah.txt");

To:
newName.open("C:\\blah.txt");
Be a part of the solution, not a part of the problem.

Roman

Damn :)  This simple thing broke many keyboards )

As far as I know You can use '/' instead of '\' on win32 too.

Regards
Roman
CB LSI (C::B as a Little Secret Initiative)

slightlyeskew

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.

darthdespotism

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

Roman

*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
CB LSI (C::B as a Little Secret Initiative)