[LC++]scanning files
Jan Pfeifer
pfjan at yahoo.com.br
Tue Sep 28 00:11:02 UTC 2004
hi Julien,
if you have access to the boost library
(www.boost.org, it's quite a "standard library") and
are used to regex patterns -- if not, consider
learning it, it's very useful! --, you could do:
using namespace boost;
static RegEx
directory_pattern("^\\s*directory\\s*=\\s*([^
\t].*)$");
if ( ! directory_pattern.Match( my_string ) )
throw ...
string directory = directory_pattern[1];
i haven't checked the regex, you can adapt it as you
see fit -- as i declared it, the directory should
start with something different than space.
i hope it helps :)
jan
ps.: from the boost library page: " ... Ten Boost
libraries will be included in the C++ Standards
Committee's upcoming C++ Standard Library Technical
Report as a step toward becoming part of a future C++
Standard. ..."
--- Julien Claassen <julien at c-lab.de> escreveu:
> Hi all!
> I have a simple probelm, but seem to be completely
> stupid. I have a file,
> with a simple format, imagine that:
> Filename is myfile.cfg
> Entry in this file is:
> directory = /usr/share/something
> Now I want to read this in a variable. With c I
> would have done:
> ...
> fscanf(file_pointer,"directory = %s",&my_string);
> ...
> How would I do this with c++ in an ellegant
> manner? I thought of
> stringstreams, but well... I'm completely lost...
> Any help is appreciated and greatfully taken!
> Kindest regards
> Julien
>
> --------
> Music was my first love and it will be my last (John
> Miles)
>
> ======== FIND MY WEB-PROJECT AT: ========
> http://ltsb.sourceforge.net - the Linux TextBased
> Studio guide
>
> _______________________________________________
> This is the Linux C++ Programming List
> :
> http://lists.linux.org.au/listinfo/tuxcpprogramming
> List
>
_______________________________________________________
Yahoo! Messenger 6.0 - jogos, emoticons sonoros e muita diversão. Instale agora!
http://br.download.yahoo.com/messenger/
More information about the tuxCPProgramming
mailing list