wtf!! stupid forum cuts off everything after the less than symbol apparently...
but it works fine in the preview
Is there a limit to the size of a file that ifstream can load?
Quote:Original post by Anonymous Poster
wtf!! stupid forum cuts off everything after the less than symbol apparently...
but it works fine in the preview
Because it strips out that tag for AP's, which can't use hyperlinks. Use < instead.
wait! It still doesn't work for me. Now, the fail bit is set, although nice catch with the semicolon thing. I hate it when I do that.
[EDIT] I just ran it again, and I think its looping through each line of the file, but its just getting a newline. Let me look some more.
[EDIT] I just ran it again, and I think its looping through each line of the file, but its just getting a newline. Let me look some more.
Quote:Original post by Drew_Benton
[smile] Note that running the program might take a bit, I think you will need to fix your Fix function as well. A 7MB file is generated from that data source.
that is probably because the file is delimited by 0A (hex) instead of the usual 0D0A. Also, you might want to see if there is some kind of tokenizer function, it would make your life easier. Then you can just keep the first token, skip three, keep the next, skip three, ...etc
Quote:Original post by Anonymous Poster
that is probably because the file is delimited by 0A (hex) instead of the usual 0D0A. Also, you might want to see if there is some kind of tokenizer function, it would make your life easier. Then you can just keep the first token, skip three, keep the next, skip three, ...etc
I agree, if all that is beging done is replacing the tabs... I'd use something like this. Then you can simply make a new string with token1 + " " + token2 + " " + token3 and be done rather than all that looping.
wait, wait, I think I'm tracking it down. Replaced readline function with simple
std::getline( fin, ret );
and now thats working... so something it wrong with the fix function. just a minute.
std::getline( fin, ret );
and now thats working... so something it wrong with the fix function. just a minute.
done! correct source:
It wasn't returning after it reached a space - it was looping back to the beginning of the line, further one. So if the line was
MARY 1 2
It would do this:
MARY
ARY
RY
Y
etc.
YEARGH!! Thanks you guys, that could have taken a long time ( especially finding that crappy semicolon). Awesome.
#include <fstream>#include <iostream>#include <string>#include <vector>std::string readline( std::ifstream & fin ){ std::string ret; char c; std::getline( fin, ret ); return ret;}std::string fix ( std::string line ){ std::string ret; for ( unsigned i=0; i<line.length(); ++i ) { if( line!=' ' ) { for ( unsigned j=i; j< line.length(); ++j ) { if ( line[j]==' ' ) return ret; ret += line[j]; } } } return ret;}int main(){ std::string filename_in, filename_out; std::string line; std::cout << "Enter filename to fix: "; std::getline ( std::cin, filename_in ); std::cout << "Enter filename for output: "; std::getline ( std::cin, filename_out ); if ( filename_in == filename_out ) { std::cout << "Can't use the same file! Abort.\n"; std::cin.get(); return 1; } std::ifstream fin ( filename_in.c_str(), std::ifstream::in ); if (!fin) { std::cout << "Could not open " << filename_in << " for reading!\n"; std::cin.get(); return 1; } std::ofstream fout ( filename_out.c_str(), std::ifstream::out ); if (!fout ) { if (fin) fin.close(); std::cout << "Could not open " << filename_out << " for writing!\n"; std::cin.get(); return 1; } std::cout << "Files opened successfully\n"; while ( line = fix ( readline ( fin ) ), fin.good() ) { fout << line << "\r\n"; } if ( !fin.good() ) { std::cout << "good: " << fin.good() << std::endl << "fail: " << fin.fail() << std::endl << "bad : " << fin.bad() << std::endl << "eof : " << fin.eof() << std::endl; } fout.close(); fin.close(); std::cout << "Operation successful.\n"; std::cin.get(); return 0;}
It wasn't returning after it reached a space - it was looping back to the beginning of the line, further one. So if the line was
MARY 1 2
It would do this:
MARY
ARY
RY
Y
etc.
YEARGH!! Thanks you guys, that could have taken a long time ( especially finding that crappy semicolon). Awesome.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement