468,272 Members | 2,143 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,272 developers. It's quick & easy.

problem with boost::regex compilation

Hello,

did anyone of You have problems using boost::regex ?

That code below :

#include "boost/regex.hpp" /*1*/
int main() /*2*/
{ /*3*/
boost::regex reg("*"); /*4*/
return 0; /*5*/
} /*6*/

isn't working on my Dev-CPP & gcc compilers :/

boost::basic_regex<char, boost::regex_traits<char,
boost::cpp_regex_traits<char>
::assign(char const*, char const*, unsigned int)]+0x22):main.cpp: undefined
reference to `boost::basic_regex<char, boost::regex_traits<char,
boost::cpp_regex_traits<char >::do_assign(char const*, char const*,
unsigned
int)'
collect2: ld returned 1 exit status

...ane weird is that
1) libraries such as pool, lexical_cast itp. work well
2) after commenting line /*4*/ program compile succesfully

have anyone any suggestions ?

Kamil 'neino'
Jan 2 '08 #1
3 2300
ne***@wp.pl wrote:
did anyone of You have problems using boost::regex ?
only from an aesthetically POV ;-)
That code below :

#include "boost/regex.hpp" /*1*/
int main() /*2*/
{ /*3*/
boost::regex reg("*"); /*4*/
return 0; /*5*/
} /*6*/

isn't working on my Dev-CPP & gcc compilers :/
DEV-Cpp in its newest incarnation contains
gcc 3.4.3, I'd rather not expect the boost
to work on that properly (maybe there is a
port I don't know of).

Under gcc 4.1.2, your snippet (neino.cxx) works fine:

$ gcc -o neino neino.cxx -lboost_regex

and without warnings.
Regards

M.
Jan 2 '08 #2
do You have boost in 1.33 version ?
Jan 3 '08 #3
ne***@wp.pl wrote:
do You have boost in 1.33 version ?
Yes, it is 1.33
BTW.: I tested it on some topics
and would say it's /somehow/ usable -
if[f] raw-strings will be in the
language.

In the frame of a current project, I tried to read
cartesian coordinates and their molecule descriptors
from a simple text file ((just for fun - to test
boost::regex):

[sample text file]
...
36.01645 33.35185 214.75779 OXYGEN 1518 1
36.98106 32.87680 214.22500 CARBON 1518 1
37.78489 32.48092 213.78100 CARBON 1518 1
...
[100_000's of lines to follow]

After the file has been slurped into a std::string,
the following snippet will extract the above data:

...
std::string::const_iterator start, end; // iterators on the buffer
start = file.str().begin(), end = file.str().end();

match_flag_type flags = match_default; // match_continuous;

regex atm("^"
" [\\t\\ ]* ([\\d.]+) [\\t\\ ]+ ([\\d.]+) [\\t\\ ]+ ([\\d.]+) "
" [\\t\\ ]+ ([\\w.]+) "
" [\\t\\ ]* (\\d*) [\\t\\ ]* (\\d*) "
"$",
regex::mod_x);

// - - - - - now read all atoms from string buffer - - - - - //
smatch coord;

while( regex_search(start, end, coord, atm) ) {
std::cout << coord[1] << '\t' << coord[2] << '\t' << coord[3] << '\t'
<< coord[4] << '\t'
<< coord[5] << '\t' << coord[6] << '\t' << std::endl;
// update search position:
start += coord[0].length()+1; // important: advance behind current match
flags |= match_prev_avail; // update flags
}
...
This may look awkward for now, but after seeing the /raw string/
in C++, this might be quite usable ...
Regards

M.
Jan 3 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Richard Latter | last post: by
5 posts views Thread by FBergemann | last post: by
reply views Thread by amrnablus | last post: by
3 posts views Thread by MCH | last post: by
13 posts views Thread by brad | last post: by
2 posts views Thread by brad | last post: by
reply views Thread by mark | last post: by
3 posts views Thread by rottmanj | last post: by
reply views Thread by zattat | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.