So now looking at line 2, Cow- DNA Sequence; this continues on line 13 and 24 and ... I want to get this long sequence for each sequences ignoring the white space and new line in between.
This is the format of the file: 1
This is the code, which reads the first 10 sequences only
ifstream file ("txt");
string line;
vector <string> vec;
stringstream s;
string name;
string strip(string & s)
{
size_t b = s.find_first_not_of(' ');
size_t e = s.find_last_not_of(' ');
if (b == string::npos) {
return "";
} else {
return s.substr(b, e - b + 1);
}
}
void getSequence(){
int i;
int row;
int col;
if (file.is_open())
{
file >> row >> col;
for (i = 0; i < row; i++) {
vec.push_back("");
}
i = 0;
while (getline(file, line))
{
file >> name;
if (line == " ")
{
continue;
}
vec[i % row] += strip(line);
i++;
}
}
else {
cerr << "Error: file did not open!" << endl;
}
for (const string & v : vec) {
cout << v << endl;
}
}
Thank you in advance for your help.
Aucun commentaire:
Enregistrer un commentaire