Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: Cant read text files?

  1. #1
    Join Date
    Mar 2007
    Beans
    Hidden!
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Cant read text files?

    Hey!

    I have a very simple program, nothing much:

    Code:
    #include <iostream>
    #include <stdio.h>
    #include <fstream>
    #include <sstream>
    
    using namespace std;
    
    string InfoCollectDataHolder;
    
    class ParseText
    {
        public:
            ParseText();
            ~ParseText();
            void Parse();
        protected:
    };
    
    ParseText::ParseText()
    {
    
    }
    
    ParseText::~ParseText()
    {
    
    }
    
    void ParseText::Parse()
    {
        ifstream FileToParse("InfoCollect.txt");
    
        if (FileToParse)
        {
            ostringstream oss;
    
            oss << FileToParse.rdbuf();
    
            InfoCollectDataHolder = oss.str();
        }
    
        else
        {
            InfoCollectDataHolder = "Sorry, couldn't open file...";
        }
    
        cout<<InfoCollectDataHolder;
    }
    
    int main()
    {
        ParseText ParseExample;
        ParseExample.Parse();
        cin.get();
    }
    And of course right next to it, I have the text file it wants. But it just gives me the error, showing it can't open the file...

    Any clue on this one?

    Thanks!
    FlyingIsFun1217

  2. #2
    Join Date
    Mar 2007
    Beans
    Hidden!
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: Cant read text files?

    Anybody?

    Thanks again!
    FlyingIsFun1217

  3. #3
    Join Date
    Jul 2005
    Location
    2 exits past crazy
    Beans
    4,223
    Distro
    Lubuntu 12.10 Quantal Quetzal

    Re: Cant read text files?

    Remove:
    Code:
    #include <stdio.h>
    and it works fine.

  4. #4
    Join Date
    Mar 2007
    Beans
    Hidden!
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: Cant read text files?

    is stdio.h a windows only type header?

    Thanks, will do!
    FlyingIsFun1217
    ----------EDIT----------

    Hmm... still doesn't work... :/

    FlyingIsFun1217
    Last edited by FlyingIsFun1217; April 8th, 2007 at 09:39 PM.

  5. #5
    Join Date
    Nov 2004
    Location
    Clemson, SC
    Beans
    271

    Re: Cant read text files?

    Quote Originally Posted by FlyingIsFun1217 View Post
    is stdio.h a windows only type header?

    Thanks, will do!
    FlyingIsFun1217
    ----------EDIT----------

    Hmm... still doesn't work... :/

    FlyingIsFun1217
    stdio.h is for C I/O, so you don't need it. And check your file names and path again, this program works just fine for me.

  6. #6
    Join Date
    Oct 2006
    Beans
    255
    Distro
    The Feisty Fawn Testing

    Re: Cant read text files?

    I know this sounds stupid, but you're sure the names are exactly the same? I spent like 5 hours discovering that one once.

  7. #7
    Join Date
    Mar 2007
    Beans
    Hidden!
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: Cant read text files?

    Me too. That taught me! Now I just copy the filename straight to the file
    I would think that the paths are correct. Its right next to it...
    I'll try just restarting C::B and see if it just didn't need restarted. That seems to happen from time to time... :/

    FlyingIsFun1217

  8. #8
    Join Date
    Mar 2007
    Beans
    Hidden!
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: Cant read text files?

    Ok, I don't know what's going on. It still doesn't work!
    Is the fault most likely in the IDE? C::B has screwed around before with my stuff.

    FlyingIsFun1217

  9. #9
    Join Date
    Jul 2005
    Location
    2 exits past crazy
    Beans
    4,223
    Distro
    Lubuntu 12.10 Quantal Quetzal

    Re: Cant read text files?

    I just copy and pasted it into a text file and used g++ to compile it. I copied the source code into the data file too, then ran the a.out that g++ produced. The code was echoed to the screen as it should have been. Try doing it that way and see if it works. If so, then it must be your IDE that is messsing things up. If not, you have bigger problems...

  10. #10
    WW is offline Iced Blended Vanilla Crème Ubuntu
    Join Date
    Oct 2004
    Beans
    1,532

    Re: Cant read text files?

    I can confirm what yabbadabbadont said. With or without stdio.h, the program compiles and runs fine for me. I also opened it up in Code::Blocks (version svn 3816--the April 6 build), and it also compiles and runs fine when I hit F9 ("Build and Run").

    I am new to Code::Blocks, so I don't know all its options. Perhaps you are running it in a way that makes it execute the program in a different directory? Take a look in the "Messages" area. What is the command that it is using to run the program?
    Last edited by WW; April 10th, 2007 at 12:43 PM.

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •