getline confusion
Feb 2, 2010 at 3:58am UTC
I am writing a quick little program to read in a file with DNA sequence and then just output just the DNA. I can get it to output the DNA how I want, but I want it to drop some header information in the file. Right before the DNA starts there is a line with "ORIGIN" so my plan was to use getline to get each line check if it has ORIGIN in it then start getting the DNA sequence.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main()
{
string inputname;
string outputname;
string linein;
char nucleotide;
ifstream seqin;
ofstream seqout;
cout << "Enter the file input name:" ;
getline (cin, inputname);
cout << "Enter the output name:" ;
getline (cin, outputname);
seqin.open(inputname.c_str());
seqout.open(outputname.c_str());
while (!seqin.eof())
{
seqin.getline(cin, linein);
if (linein == "ORIGIN" )
{
while (!seqin.eof())
{
seqin.get(nucleotide);
if (nucleotide == 'a' )
{
seqout << nucleotide;
}
if (nucleotide == 'g' )
{
seqout << nucleotide;
}
if (nucleotide == 'c' )
{
seqout << nucleotide;
}
if (nucleotide == 't' )
{
seqout << nucleotide;
}
if (nucleotide == 'A' )
{
seqout << nucleotide;
}
if (nucleotide == 'G' )
{
seqout << nucleotide;
}
if (nucleotide == 'C' )
{
seqout << nucleotide;
}
if (nucleotide == 'T' )
{
seqout << nucleotide;
}
}
}
else
{
}
}
seqin.close();
seqout.close();
return 0;
}
Any help would be greatly appreciated, I haven't done much C++ programming in a couple years so quite rusty.
Feb 2, 2010 at 4:16am UTC
line 29: instead of
seqin.getline(cin, linein);
getline(seqin, linein);
Feb 3, 2010 at 2:58am UTC
That compiles fine thanks pyschoder. Any idea why it just outputs a blank file? Is it fine to have 2 whiles with eof ?
Feb 3, 2010 at 3:01am UTC
nevermind I got it there were spaces on the line so it wasn't seeing it as being equal.
Thanks again pyschoder
Topic archived. No new replies allowed.