Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ Moderated > Re: Filestream ...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 6 of 7 Topic 9506 of 9983
Post > Topic >>

Re: Filestream problems

by Carl Barron <cbarron413@[EMAIL PROTECTED] > Apr 17, 2008 at 07:35 PM

In article
<fd3a6fb3-a114-41a8-9219-dc7efbeb3331@[EMAIL PROTECTED]
>,
Hani Sharabash <HaniBash@[EMAIL PROTECTED]
> wrote:

> On Apr 17, 3:56 am, Carl Barron <cbarron...@[EMAIL PROTECTED]
> wrote:
> > In article
> > <73c37290-e418-4d12-934a-c33075210...@[EMAIL PROTECTED]
>,
> >
> > Hani Sharabash <HaniB...@[EMAIL PROTECTED]
> wrote:
> > > I'm writing a program in which I read text from a file, store all of
> > > the words into a binary search tree, and then print the words out to
> > > the screen in order from that tree.
> >
> > > For some reason, opening and using an input filestream is causing
> > > problems for my binary tree functions. When I try to use them
> > > together, my program crashes at runtime. For example:
> > > \
> >
> >     first I would make sure where the error is in this case I would
> > imput the data and store it in a stanard sorted assoc. container
> > say std::set<std::string> and print the results from
> > std::set<std::string> before I blame <fstream>  probably there is
> > a bug in your binary tree code. But if reading it into an
> > std::set<string> works then its not <fstream>.
> >
> 
> I don't understand. Could you clarify a little more?

   std::set<std::string> will hold the sorted words with persumably
working code as std::set is 10 years old approx. and should be free
of internal errors.

   if you read from <fstream> as you currently do but store the words in
an std::set<std::string>  dups are removed , if you want dups then
multi_set<std::string> will work as well.

#include <fstream>
#include <set>
#include <algorithm>
#include <iterator>
#include <iostream>

int main()
{
   std::ifstream  in_file(...);
   std::set<std::string> words;
   while(in_file)
   {
      std::string this_word;
      // your reading code that reads one word into this_word.
      words.insert(this_word);
   }
   // print out results:
  
std::copy(words.begin(),words.end(),std::ostream_iterator<std::string>
      (std::cout,"\n"));
}

now the only possible problem [unless this is an ancient compiler] is in
the reading code.  further if this provides what you really want its
done,

-- 
      [ See http://www.gotw.ca/resources/clcm.htm
for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]
 




 7 Posts in Topic:
Filestream problems
Hani Sharabash <HaniBa  2008-04-16 11:38:04 
Re: Filestream problems
Michael.Boehnisch@[EMAIL   2008-04-17 03:49:28 
Re: Filestream problems
Ulrich Eckhardt <eckha  2008-04-17 03:59:44 
Re: Filestream problems
Carl Barron <cbarron41  2008-04-17 03:56:36 
Re: Filestream problems
Hani Sharabash <HaniBa  2008-04-17 16:20:31 
Re: Filestream problems
Carl Barron <cbarron41  2008-04-17 19:35:45 
Re: Filestream problems
"Thomas J. Gritzan&q  2008-04-17 19:34:04 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sun Sep 7 4:00:09 CDT 2008.