1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

sun string comparison

Discussion in 'C++' started by heidik, Dec 2, 2010.

  1. heidik

    heidik New Member

    Joined:
    Oct 23, 2010
    Messages:
    69
    Likes Received:
    0
    Trophy Points:
    0
    Hello everyone.

    I am reading strings from file and I have to identify strings that are similar to eachother but on the basis of a substring i-e if a substring of the two/more strings match then the two/more strings would be considered similar.

    Code:
    istringstream ss(line);
    getline(ss,ordb.lineID,','); 
    getline(ss,ordb.dateTime,',');
    getline(ss,ordb.remSTr); 
    
    // Check if the "lineID + remSTr" combination is already in the vector.
    // If it is, compare dates and use the lesser one
    
    
    // how do I compare a substring here? the substring for comparison consists of lineID and remSTr. If lineID and remSTr are similar then the two/more strings would be similar.
    vector<ordRecvblock>::iterator it = find(OrdTime.begin(),OrdTime.end(),ordb);
    
    if (it != OrdTime.end())
    {
          if (ordb.dateTime < it->dateTime)
          {
                cout << it->lineID << ',' << it->dateTime << ',' << it->remSTr << endl;
    
                *it = ordb;
          }
          else
          {
                cout << ordb.lineID << ',' << ordb.dateTime << ',' << ordb.remSTr << endl;
          }
    }
    /*else
    {
          OrdTime.push_back(ordb);
    }*/
    
     

Share This Page