User forums > General (but related to Code::Blocks)

fstream issues

(1/2) > >>

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:

--- Code: ---newName.open("C:\blah.txt");
--- End code ---

To:

--- Code: ---newName.open("C:\\blah.txt");
--- End code ---

Roman:
Damn :)  This simple thing broke many keyboards )

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

Regards
Roman

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.

--- End quote ---
That's correct

Navigation

[0] Message Index

[#] Next page

Go to full version