Does reading file with fstream not work on xp?

This is a discussion on Does reading file with fstream not work on xp? within the C++ Programming forums, part of the General Programming Boards category; Hi, I have made a program but it doesn't run properly on windows xp? In the program I use fstream ...

  1. #1
    Registered User
    Join Date
    Mar 2002
    Posts
    112

    Does reading file with fstream not work on xp?

    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?

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >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
    My best code is written with the delete key.

  3. #3
    Registered User blight2c's Avatar
    Join Date
    Mar 2002
    Posts
    266
    i've never had a problem, post your code maybe i can help

  4. #4
    Registered User matheo917's Avatar
    Join Date
    Sep 2001
    Posts
    279
    fstream. --- compiles fine on XP

  5. #5
    Registered User
    Join Date
    Mar 2002
    Posts
    112
    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);
    }

  6. #6
    Fingerstyle Guitarist taylorguitarman's Avatar
    Join Date
    Aug 2001
    Posts
    564
    Why not try and check that the file is opened properly? (Maybe it's not in the right place)

    /* edit: don't harass prelude */
    If a tree falls in the forest, and no one is around to see it, do the other trees make fun of it?

  7. #7
    Registered User blight2c's Avatar
    Join Date
    Mar 2002
    Posts
    266
    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);
    Last edited by blight2c; 04-10-2002 at 10:25 PM.

  8. #8
    Registered User
    Join Date
    Mar 2002
    Posts
    112
    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.

  9. #9
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >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:
    Code:
    if ( !file.isopen() )
      cout<<"Not a code problem\n";
    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.

    -Prelude
    My best code is written with the delete key.

  10. #10
    Registered User
    Join Date
    Mar 2002
    Posts
    112
    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.

  11. #11
    Registered User xds4lx's Avatar
    Join Date
    Nov 2001
    Posts
    630
    Hehe i prefer to call the good method lol
    Code:
    if(file.good())
    {    .......
    }
    "only two things are infinite, the universe and human stupidity, and im not sure about the former." - albert einstein

  12. #12
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >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
    My best code is written with the delete key.

  13. #13
    Its not rocket science vasanth's Avatar
    Join Date
    Jan 2002
    Posts
    1,683
    It works for me

  14. #14
    Registered User heat511's Avatar
    Join Date
    Dec 2001
    Posts
    169

    speaking of text files....

    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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. help with text input
    By Alphawaves in forum C Programming
    Replies: 8
    Last Post: 04-08-2007, 05:54 PM
  2. Encryption program
    By zeiffelz in forum C Programming
    Replies: 1
    Last Post: 06-15-2005, 04:39 AM
  3. Simple File encryption
    By caroundw5h in forum C Programming
    Replies: 2
    Last Post: 10-13-2004, 11:51 PM
  4. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 10:54 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21