Skipping lines with specified character

Dear all,

I have a dataset that looks like this:
1
2
3
4
5
6
AAAAACTGC
..ACTCGGG
ACGGGGAAA
.........
ACGGG...G
AATGAAAAA


What I want to do is to skip all the lines that has "dot"
in them, yielding:

1
2
3
AAAAACTGC
ACGGGGAAA
AATGAAAAA


Is there any simple way to achieve that in C++?

I'm stuck with this code:
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
#include <iostream>
#include <vector>
#include <fstream>
#include <sstream>
using namespace std;


int main  ( int arg_count, char *arg_vec[] ) {
    if (arg_count !=2 ) {
        cerr << "expected one argument" << endl;
        return EXIT_FAILURE;
    }

    string line;
    ifstream myfile (arg_vec[1]);


    if (myfile.is_open())
    {
        while (getline(myfile,line) )
        {
                stringstream ss(line);
            string DNA;

            while (ss >> DNA) {
                
                // not sure how to skip here
                cout << DNA << endl;
            }


        }
        myfile.close();
    }

    else cout << "Unable to open file"; 
    return 0;
}



Use getline() to store the line in a string. Then you can use the memberfunction find() (http://www.cplusplus.com/reference/string/string/find.html) to see or there is a dot in the line. If not (find() will return npos), you can print the string on the screen/write it to a file:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>

using namespace std;

int main()
{
    string a="123.567";
    string b="1234567";
    if (a.find(".")==a.npos)
        cout<<a<<endl;
    if (b.find(".")==b.npos)
        cout<<b<<endl;
    cin.ignore();
    return 0;
}
Last edited on
1
2
 if ((int)DNA.find(".") > 0)
   continue;
Topic archived. No new replies allowed.