CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Dec 2011
    Posts
    1

    Question Reading my textfile as blank

    Here's an excerpt from my code:
    Code:
    void SparseMatrix2D::read(std::string filename) {
    	std::ifstream inp, in;
    	in.open(filename.c_str(), std::ios::in);
    	if(in.is_open()) {
    		std::vector<double> cols;
    		while(! in.eof() ) {
    			char c;
    			in.get(c);
    			if(c == '\n') {
    				matrix.push_back(cols);
    				while(cols.size() > 0)
    					cols.erase(cols.begin());
    			}
    			else {
    				double d;
    				in >> d;
    				cols.push_back(d);
    			}
    		}
    		in.clear();
    		in.close();
    	}
    	else {
    		std::cout << "file: " << filename << " could not be opened." << std::endl;
    	}
    }
    When I call this function the first time, sure enough it reads in the textfile as I want. The next time I call this function, with a different textfile it only reads in blanks. It doesn't pick up any newlines or anything else.

    The textfiles haven't been corrupted or modified in anyway either.

    Any help?

  2. #2
    Join Date
    May 2001
    Location
    Germany
    Posts
    1,158

    Re: Reading my textfile as blank

    Did yo step through the function with your debugger?

Tags for this Thread

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured