Get stringstream with separator!!!

This is a discussion on Get stringstream with separator!!! within the C++ Programming forums, part of the General Programming Boards category; I did add the bintree insert outsite the loop. The numNodes() increase but i cannot get the display because: words ...

  1. #31
    Registered User
    Join Date
    May 2009
    Posts
    30
    I did add the bintree insert outsite the loop. The numNodes() increase but i cannot get the display because: words w(new_word) is inside the loop.

    Btw, base on the code above the display go weird.

    Today
    is-not-a-good-day
    (newline here free)
    the
    problem
    is
    this
    "
    "More.about.decimal
    ... // word continue here until
    2This
    quote
    ...
    will

    num Node is: 23

    there are 2 things on the display "More and 2This. two line stick together while others work fine ??? and newline automatically add there ???

    Please...

  2. #32
    Registered User
    Join Date
    May 2009
    Posts
    30
    I have inserted and printed out the bintree (automatically sorted)
    but there still one problem

    Code:
    while (fin.good())
    
          {
    
             getline(fin, temp);
    
             string::const_iterator itr = temp.begin();
    
             while(itr != temp.end())
    
             {
    
                 if (isspace(*itr) || *itr == '>' || *itr == '<'  || *itr == '!' || *itr == ',') 
    
                {
    
                   if (word.find(new_word))
    
                   {
    
                         i++;
    
                         new_word.clear();
    
                   }
    
                   else
    
                   {
    
                      word.insert(words(new_word));
    
                       new_word.clear();
    
                   }
    
                }
    
                else
    
                {
    
                   new_word += *itr;
    
                }
    
                itr++;
             }
    
          }
    
          word.insert(words(new_word)); // this will insert the last word into bintree, but the problem is the last word is
                                                 //the same with one of the word exist. The program is terminated.
          print(word);
       }
    
    }
    
    //print function which called toString above
    void print(bintree<words> word)
    {
       cout << "COUNT | WORD \n";
       cout << "------+------\n";
       word.print();
       cout << "\nNum Nodes is: " << word.numNodes() << endl;
    }
    Everytime i wanna insert into bintree i have to check it again whether the word is already exist or not.
    I'm thinking of a bool function for finding an exsting word then apply to where i wanna insert.

    is there any more convinient way to do this???
    Thanks

Page 3 of 3 FirstFirst 123
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. stringstream problem
    By black_spot1984 in forum C Programming
    Replies: 3
    Last Post: 10-28-2008, 04:09 PM
  2. stringstream clear
    By misterowakka in forum C++ Programming
    Replies: 3
    Last Post: 01-01-2008, 12:03 PM
  3. Socket: send stringstream
    By crisis in forum C++ Programming
    Replies: 5
    Last Post: 11-22-2007, 09:50 AM
  4. static separator
    By Bleech in forum Windows Programming
    Replies: 2
    Last Post: 10-21-2007, 03:47 PM
  5. Length of a stringstream
    By nickname_changed in forum C++ Programming
    Replies: 1
    Last Post: 10-24-2003, 07:30 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21