// Helper function to get a k-mer (it ignores newline characters)
void read(std::ifstream & in, std::string & string, int streamsize){
int pos=0;
// Read streamsize number of characters from stream discarting
// newline characters
while(pos<streamsize){
in >> string[pos];
++pos;
}
}
void read_file(char * file, int kmer){
// open file
std::ifstream input( file );
// check that file if okay for operations
assert(input.good());
// Current string(character) being read from file
std::string cursor;
cursor.resize( kmer );
// Position in stream
int charPos=1;
// Read file
while( !input.eof() ){
// Get a kmer from the file stream
read( input, cursor, kmer );
// If stream has not ended
if (!input.eof()){
std::cout<< cursor <<'\n';
}
else { break; }
// Save place in stream
input.seekg( charPos++ );
}
// Close file
input.close();
}
But this outputs:
ABC
BCD
CDE
DEL
ELM
LMN
LMN
MNO
NOP
The problem is that I don't know how to avoid the function seekg step back but avoid newline chaaracters. Does anyone know how to overcome this?