--- In [email protected], "akhila_3" <[EMAIL PROTECTED]> wrote:
>
> Well 
> "while (getline (ifs, tmp))"
> does not work. i cant use a file ifs.. i have to use a string...
> i got an error saying it was not a valid expression..
> is there an alternative way of doing this?
> 
> Thanks 
> 
> 
> 
> 
> --- In [email protected], "Tamas Marki" <tmarki@> wrote:
> >
> > On 3/29/07, akhila_3 <akhila_3@> wrote:
> > >  the line i am trying to read looks something like this:
> > >  cfg.?.readline=("string1,string2");
> > >
> > >  there are a 1000 lines in the file that begin with cfg but 
only 
> 1 that
> > >  has "readline" in it. also i dont know wat variable1 and 
> variable2 are
> > >  (there could be more than 2 strings. i am not supposed to know 
> the
> > >  count either). i have to read them in and print them out.
> > >
> > >  the other thing is the config file is located in another dir.
> > >
> > >  Can you please tell me how i can extract the line from the 
config
> > >  file. i was thinking of using fgets... but was not sure if C++ 
> had a
> > >  better way of doing this?
> > >  n also how exactly does getline work?
> > 
> > Real simple. Consider (untested, simplified, but should work):
> > 
> > ifstream ifs ("/path/to/filename");
> > string tmp;
> > while (getline (ifs, tmp))
> > {
> >   cout << tmp << endl; // echo line or process it
> > }
> > 
> > 
> > -- 
> > Tamas Marki
> >
>

If you are working with a string instead of a file the following can 
be done. You would need to adjust the max number to your requirements.


istringstream Stream(Str);
const int max(100);  
char buf[max];
Stream.getline(buf, max);


Mickey


Reply via email to