Q:

Reading Lines after a line in C++ not working

I've spent like 2 hours trying to parse the following bytes from a file :
>Rosalind_6404
CCTGCGGAAGATCGGCACTAGAATAGCCAGAACCGTTTCTCTGAGGCTTCCGGCCTTCCC
TCCCACTAATAATTCTGAGG
>Rosalind_5959
CCATCGGTAGCGCATCCTTAGTCCAATTAAGTCCCTATCCAGGCGCTCCGCCGAAGGTCT
ATATCCATTTGTCAGCAGACACGC
>Rosalind_0808
CCACCCTCGTGGTATGGCTAGGCATTCAGGAACCGGAGAACGCTTCAGACCAGCCCGGAC
TGGGAACCTGCGGGCAGTAGGTGGAAT

I would like to store the word Rosalind_, and store every line, concatenate all, and have just one string having all the lines. 
I tried the following code, but it still doesn't work probably, I always miss the last line. 
int main()
{
    std::ifstream infile("data_set.txt");
    map < int, string > ID;
    map < int, string > dataSetMap;
    int idNumber= 0;
    int idDataSetNumber = 0;

    std::string line;
    std::vector<string> dataSetString;
    std::string seqid;

    while (!infile.eof() )
    {

        while(std::getline(infile, line))
        {

            if ( line.substr(0,1)== ">")
            {

                conct = "";
                seqid = line.substr(1,line.length() - 1);   
                ID.insert(make_pair( idNumber++, seqid));
                lineNumber = 0;
                line.clear();
                std::string data= "";
                if(dataSetString.size()>0)
                {
                    for (int i = 0; i<dataSetString.size(); i++)
                    {
                        data+=dataSetString[i];
                    }
                    dataSetMap.insert(make_pair(idDataSetNumber++, data));
                }
                dataSetString.clear();
            }

            if(!line.empty() )
            {

                dataSetString.push_back(line);
            }

        }

    }

I'm trying to practice problems solving approaches, and that really gave me headache. 
I'm looking for a better approach also.

A:

This code does what you want: 
#include <map>
#include <vector>
#include <string>
#include <iostream>
#include <fstream>

int main()
{
    std::istream& infile = std::cin;
    std::map < int, std::string > ID;
    std::map < int, std::string > dataSetMap;
    int idNumber= 0;
    int idDataSetNumber = 0;

    std::string line;
    std::vector<std::string> dataSetString;
    std::string seqid;

    bool success = std::getline(infile, line);
    while(success) {
        if( line.substr(0,1) == ">" ) {
            seqid = line.substr(1,line.length() - 1);
            ID.insert(make_pair( idNumber++, seqid));
            std::string data;
            while(success = std::getline(infile, line)) {
                if(line.substr(0,1) == ">") break;
                data += line;
            }
            dataSetMap.insert(make_pair(idDataSetNumber++, data));
        } else {
            std::cout << "Invalid input file. It needs to start with >SOME_ID" << std::endl;
            return 1;
        }
    }

    std::cout << "Parsed data ----------------" << std::endl;
    for(std::map<int,std::string>::const_iterator it = dataSetMap.begin(); it != dataSetMap.end(); ++it) {
        std::cout << "Id: " << ID[it->first] << std::endl;
        std::cout << (it->second) << std::endl;
    }
}

It first reads a line from the input file and tries to parse it as an ID. If that fails, it returns an error. Then it reads the data until it finds another ID or EOF. It inserts the data and continues to parse the ID it found if it didn't encounter EOF.
Working demo: http://ideone.com/F4mcrc
Note: This fails when the file is empty, you might want to check for the empty string or a string containing only whitespaces in the else of the ID check and skip it. 

