problem with boost::regex compilation

N

neino

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 said:
::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'
 
M

Mirco Wahab

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.
 
M

Mirco Wahab

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,066
Latest member
VytoKetoReviews

Latest Threads

Top