[Halloween]What is your serial killer name?

Pages: 123
that's not why it doesn't work, DTSCode, but that definitely doesn't help :P
@DTSCode
He helped modify my original code. Well he posted modified code, but I never changed it. Sorry, realized how much of an jerk that sounded. Truth is that I just quickly did the code, throwing out all the rules just to get it coded fast. I wasn't expecting it to get revised so much due to it being so simple. I was perfectly happy with how it was done and moved on.
Last edited on by closed account z6A9GNh0
closed account (S6k9GNh0)
BHXSpecter, things like that catch my eye since some don't realize there are often alternatives to writing repetitive code (even if it doesn't seem repetitive). But I agree, it's just a basic program.
Yeah, I wasn't stressing over efficiency at that time. I just wanted to point out that you did deserve to receive credit as you had posted some mods to the code making it more efficient which was used in later revisions of the code.
closed account (Dy7SLyTq)
alright. you can be added. why doesnt it work cheraphy
I don't have access to a compiler that supports C++11 regex
closed account (S6k9GNh0)
You can probably just use boost::regex.
Since we're apparently going hardcore with it though, might as well bring out the Flex/Bison wombo combo to validate input.
@Cherapy

test.cc:36:28: error: invalid operands to binary expression
      ('const value_type' (aka 'const sub_match<std::__1::__wrap_iter<const char *> >') and 'int')
        Name = FirstName[match[1] - 'A'] + LastName[match[2] - 'A'];
                         ~~~~~~~~ ^ ~~~

smatch::operator[] returns an std::sub_match, which is convertible to std::string, but certainly not to char.

Furthermore, on a typical name your regex matches just one, first, capital letter of the first name, which is placed into match[3] (and also into match[0] since that's the entire match), leaving [1] and [2] empty

I was able to get your program to work with this modification (using clang++/libc++, but it also runs with gcc if std::regex is replaced by boost::regex):
1
2
3
4
    std::regex rgx("(\\b[A-Z]).* (\\b[A-Z])");
    std::smatch match;
    if( std::regex_search(Name, match, rgx)) {
            Name = FirstName[match[1].str()[0] - 'A'] + LastName[match[2].str()[0] - 'A'];

smatches work best when you can use their convertibility to string (e.g. if FirstName and LastName were map<string, string>, this would have been just FirstName[match[1]] + LastName[match[2]])

Last edited on
Thanks for the tip Cubbi. I'm wholly new to regular expressions.
Topic archived. No new replies allowed.
Pages: 123