Hi, I have made a program but it doesn't run properly on windows xp? In the program I use fstream to read some files and I'm wondering if this is the problem? If it is what other ways of reading files are there?
Printable View
Hi, I have made a program but it doesn't run properly on windows xp? In the program I use fstream to read some files and I'm wondering if this is the problem? If it is what other ways of reading files are there?
>I use fstream to read some files and I'm wondering if this is the problem?
Of course it's Windows, it couldn't possibly be your code could it? I mean, we all know every programmer in the world is perfect. 999 times out of 1000, you're program isn't finding the file because of something you did wrong. I love how everyone places the blame everywhere but themselves. It's like at the automated teller, if something bad happens people scream "stupid machine!" when "stupid user!" would be more accurate.
-Prelude
i've never had a problem, post your code maybe i can help :)
fstream. --- compiles fine on XP
Wow your an ass, I never blamed it on windows. It works fine one windows 9x so I thought maybe fstream was sort of a dos function and it might now work on xp. Anyway here is my code all it does is read every other line from a file and add it to a list box.
char buffer[150]="";
ifstream SongList ("c:\\cache");
while(!SongList.eof())
{
SongList.getline (buffer,150);
SendDlgItemMessage(hwnd, IDC_LIST1, LB_ADDSTRING, NULL, (LPARAM)buffer);
SongList.getline (buffer, 150);
}
Why not try and check that the file is opened properly? (Maybe it's not in the right place)
/* edit: don't harass prelude */
sorry, i just don't know enough. but, the best person to help you happens to be the one you just called and ass.
[edit]
i got this to work, will it help
Code:#include <fstream.h>
#define max 5
main()
{
int loop=0;
int x;
char filename[20]="a:zztest.dat";
int mode=(ios::in|ios::binary);
fstream fin (filename, mode);
if (!fin);
cerr<<"error";
while (fin>>x)
{
cout<<x<<endl;
loop++;
}
fin.close();
cout<<"all finished";
return(0);
Alright, I'll just check to see if the file opens. Anyways the code that is not working is right there. Becuase when I open the program it downloads a file to c:\cache and then it reads from the file and adds its contents to a listbox. When I run the program it works fine on my computer and my friends but when we tried it on xp it didn't work. However because the file c:\cache was still on the xp machine after the program was run I thought there was a problem with xp reading the file. Anyways sorry for calling you an ass Prelude I'm just saying wasn't really blaming it on the machine.
>Anyways sorry for calling you an ass Prelude
No, it was my fault. I was just letting out my frustration after of long day, it's nothing personal :)
If the file doesn't open you can check it by saying something along the lines of:
If the message prints then the program isn't finding the file and you should double check what it's actually looking for. Be sure to check your syntax for opening the file as well, that can cause runtime problems yet still compile without warning or error.Code:if ( !file.isopen() )
cout<<"Not a code problem\n";
-Prelude
OK, I'll just do what you said and if it comes up with the error message then I know the problem is with reading the file but if it doesn't then I'll know the problem is somewhere else.
Hehe i prefer to call the good method lol :)
Code:if(file.good())
{ .......
}
>Hehe i prefer to call the good method lol
As do I when I'm actually processing the file. When debugging however, isopen() is more precise since good() simply tells you that none of the control bits are set. good() doesn't specify whether the file couldn't be read from (ie. not open) or you've simply reached EOF (ie. empty file). Personally, I prefer more detail when debugging a problem. ;)
-Prelude
It works for me
do text files not work when you run the exe, cause they never seem to work from exe, although they work just fine when i run the program through c++ cpp file?
thanks