0

Hi all, I am trying to reading stuffs from the text file, i don't know y but program can't read off the tab space

eg.
it reads

Hi HappyDay 325

but it can't read

Hi      Happy Day           325

like where we used more than one spacing for one word or tab spacing

here is my code plz help me

void get_graph(string const &filename, NodeMap &node_map) 
{

    ifstream inf(filename.c_str());
    string from, to;
    double weight;
    while(inf.good()) 
    {
        inf >> from >> to >> weight;
        if ( inf.good() ) 
        {
            Node *Target = node_map.find_in_nodemap(to);
            Node *Source = node_map.find_in_nodemap(from);
            Edge *connector = new Edge(weight,Target);
            Source->neighbors.push_back(connector);
        }
    }
}
int main()
{
    NodeMap nodes;
    ifstream inf;
    string filename;
    cout<<"Enter filename : ";
    cin>>filename;
    inf.open(filename.c_str());
        get_graph(filename, nodes);
        .
        .
        .
}

Edited by Reverend Jim: Fixed formatting

2
Contributors
1
Reply
2
Views
8 Years
Discussion Span
Last Post by jencas
0

inf >> from >> to >> weight;

reads

Hi -> from
Happy -> to
Day -> weight

What you can do:
1) mark Happy Day as one word
Hi "Happy Day" 325
2) read with getline and parse the line appropriately

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.